C ++

C ++it is an imperative object-oriented language derived from C. Actually a superset of C, born to add qualities and characteristics that it lacked. The result is that, like its ancestor, it is still closely linked to the underlying hardware, maintaining considerable power for low-level programming, but elements have been added that also allow it a programming style with a high level of abstraction. Strictly speaking, C is not a subset of C ++; in fact it is possible to write C code that is illegal in C ++. But for practical purposes, given the compatibility effort expended in its design, C ++ can be considered an extension of classic C. The “official” definition of the language tells us that C ++ is a general-purpose C-based language, to which new data types have been added,operators , references, operators for persistent memory handling, and some additional library utilities (actually the Standard C library is a subset of the C ++ library)


[ hide ]

  • 1 A little history
  • 2 General concepts of object-oriented programming
  • 3 About the OOP
  • 4 About Interpreter and Compilers
  • 5 What can be done with C ++
    • 1 A code example
  • 6 What has been done in C or C ++?
    • 1 Operating Systems and other programs
  • 7 See also
  • 8 Sources

A little history

The committee for the ANSI C standard was formed in 1983 with the goal of creating a uniform language from the original C, developed by Kernighan and Ritchie in 1972, at ATT. Until then, the standard was set by the book written in 1978 by these two authors1. The C ++ language began development in 1980. Its author was Bjarne Stroustrup , also from ATT. In the beginning it was an extension of the C language that was named C with classes. This new language began to be used outside of ATT in 1983. The name C ++ is also from that year, and refers to the character of the C (++) increment operator. Given the great diffusion and success it was obtaining in the world of programmers, ATT began to standardize it internally in 1987 . In 1989 an ANSI committee (followed some time later by an ISO committee ) was formed to standardize it at the American and international levels. Today C ++ is a versatile, powerful and general language. Its success among professional programmers has led it to the first place as an application development tool. C ++ maintains the advantages of C in terms of operator wealthand expressions, flexibility, conciseness and efficiency. Also, it has removed some of the difficulties and limitations of the original C. The evolution of C ++ has continued with the appearance of Java, a language created by simplifying some C ++ things and adding others, which is used to make applications on the Internet. It should be noted that C ++ has influenced some very important points of ANSI C, such as how to declare functions, pointers to void, etc. Indeed, although C ++ is later than C, its first versions are earlier than ANSI C, and some of the improvements to it were taken from C ++. C ++ is both a procedural (algorithm-oriented) and an object-oriented language. As a procedural language, it resembles C and is compatible with it, although it has already been said to have certain advantages. As an object-oriented language, it is based on a completely different philosophy, which requires a complete change of mentality from the programmer.

General concepts of object-oriented programming

  • Class: It is a template that defines the structure of a set of objects, which when created will be called the instances of the class. This structure is made up of the definition of the attributes and the implementation of the operations (methods).
  • Object: It is the implementation of a class instance, that is, an occurrence of this, which has the attributes defined by the class, and on which the operations defined in it can be executed.
  • Identity: Characteristic of each object that differentiates it from the others, including those that could belong to the same class and have the same values ​​in their attributes.
  • Inheritance: It is the ability of classes to inherit properties and methods from other classes.

About the OOP

The OOP is a new programming philosophy that is based on the use of objects. The goal of the OOP is but the goal of any conventional structured programming model: to “impose” a series of development rules that ensure and facilitate the maintainability and reusability of the code. The basic mechanisms of the OOP are: objects, messages, methods and classes.

  • An object is an entity that has particular attributes (data) and ways to operate on them (member methods or functions). In other words, an object includes, on the one hand, a series of operations that define its behavior, and a series of variables manipulated by those functions that define its state. For example, a Windows window will contain operations like “maximize” and variables like “width” and “height” of the window.
  • In C ++, a message corresponds to the name of one of the methods of an object. When a message is passed to an object, it responds by executing the associated function code.
  • Method. A method (member function) is implemented inside an object and determines how the object should act when the associated message occurs. In C ++ a method corresponds to the definition of the member function of the object. The innermost structure of an object is hidden, so that the only connection to the outside is messages
  • A class is the definition of a type of objects. In this way, an “Employee” class would represent all the employees of a company, while an object of that class (also called an instance) would represent one of those employees in particular.

The main characteristics of the OOP are: abstraction, encapsulation, inheritance and polymorphism:

  • Abstraction. It is the design mechanism in the POO. It allows us to extract from a set of entities data and common behaviors to store them in classes.
  • Through this technique we will make each class a black box, so that the objects of that class can be manipulated as basic units. The details of the implementation lie within the class, while from the outside, an object will simply be an entity that responds to a series of public messages (also called the class interface).
  • It is the mechanism that allows us to create derived classes (specialization) from base classes (generalization). That is, we could have the class “Employee” (base class) and the class “Seller” deriving from the previous one. A class library (like the MFC) is nothing more than a set of class definitions interconnected by multiple inheritance relationships.
  • This feature allows us to have multiple implementations of the same class method, depending on the class in which it is performed. That is, we can access a variety of different methods (with the same name) through the same access mechanism. In C ++ polymorphism is achieved by defining derived classes, virtual functions, and the use of object pointers.

Two other very important concepts in the OOP are related to the creation and destruction of objects. In conventional structured languages, when a variable is defined memory space is reserved and, if it is not expressly initialized, it is made by default (for example, in C a global variable is always initialized to 0, but an automatic one is not, therefore, that if it is not expressly initialized, its initial content will be garbage); on the other hand, when a variable is destroyed (because the scope of its definition – scope – is abandoned), the memory it was occupying is freed. If we now make the forced parallelism between variables and objects for the POO languages ​​we will realize that there must be special procedures for the construction and destruction of objects. Specific,

  • Constructor-> Member function that is automatically invoked every time an object is defined, its objective is to initialize it. It takes the same name as the class, it can receive parameters and we can have several constructors defined.
  • Destroyer-> Member function automatically invoked every time an object is destroyed. Its objective is to perform operations such as memory release, closing open files, etc. It takes the same name of the class first started by the character “~”, it does not take parameters and it does not support overloading (there can only be one in each class).

In many cases, for the simplest classes, we can find classes that do not have a constructor or a destructor, or neither. In C ++, there are always default constructors and destructors that perform a standard initialization / release.

About Interpreter and Compilers

Before, mention that both C and C ++ are compiled languages, and not interpreted. This difference is very important, since it greatly affects many aspects related to program execution. In interpreted language, the program is written in text form, it is the source program itself. This source program is processed by an external program, the interpreter, which translates the program, instruction by instruction, while executing it. In interpreted languages ​​there are no programs executable directly by the computer. The interpreter translates, in real time, each line of the source program, each time you want to run the program. In compiled languages ​​the translation process is only done once. The compiler program takes as input the source code of the program, and outputs a file that can be directly executed by the computer. Once compiled, the executable program is autonomous, and it is no longer necessary to have the original program or the compiler to run it. Each option has its advantages and disadvantages, and some features that are considered an advantage can be a disadvantage in certain circumstances, and vice versa.

  • The interpreted languages ​​are easily modifiable, since we need to have the source code available on the computer. In compilations, these files are not necessary, once compiled.
  • Interpreted languages ​​need an external program, called an interpreter or sometimes a virtual machine, or framework. This program acts as an intermediary between the source and the operating system. In compiles, that role is played by the compiler, but unlike the interpreter, once it has done its job, you do not need to be present to run the program.
  • These two characteristics, logically, make compiled programs require less memory space than interpreted ones (if we count the space used by the interpreter), and in general, the compiled ones are faster, since they are only compiled once, and the Time spent on that task does not add to that of execution.

Interpreted languages ​​include: BASIC (General Purpose Instruction Code for Beginners), Java, PHP . Many scripting languages ​​etc. Among the compiled languages ​​are: C, C ++, Pascal.

What can be done with C ++

What kind of programs and applications can be created using C and C ++? The answer is very simple: EVERYONE. Both C and C ++ are general-purpose programming languages. Everything can be programmed with them, from operating systems and compilers to database applications and word processors, through games, custom applications, etc.

A code example

This is the classic Hello World program, the idea is focused on the birth of a new program from the hands of its creator.

#include  <iostream>


using  namespace  std ;


int  main ()


cout  <<  “Hello world”  <<  endl ;

return  0 ;


What has been done in C or C ++?

Operating Systems and other programs

  • Just like Unix, the predecessor of this operating system, GNU / Linux– often referred to only as Linux , which is the name of the kernel of the OS – makes use of a good number of programming languages ​​in its different components. What are those languages? Each type of resource seems to have certain preferences, and that is that there are more suitable languages ​​for some things. Obviously the C programming language is still the foundation, but much more is involved.
  • Kernel and device drivers: Both the drivers and the kernel operate at a really low level of operations on the computer. To write the operating system kernel and access hardware properties such as memory cycles, input / output buses, etc., you need a language that can communicate with the hardware powerfully. The Linux kernel uses the C language (although it is not really a low-level language) with a small part in the assembly language.
  • Libraries and Utilities: Basic system libraries and utilities such as mkdir, chmod, chown, head, tail, chroot, uptime, users are also written in C language.
  • Package managers and configuration programs: Package managers such as yum, apt, dpkg, etc., are also written in C, which as you can see is the absolute star of the “base” components of a GNU / Linux system.
  • Desktop environments and window managers: Most people use a desktop environment, and today there is little left only in the command line interface. Window managers such as metacity, kwin are developed in C and require gcc to be compiled. The desktop environment, icons, windows, toolbars, etc., are based on specific libraries (Qt for KDE, GTK + for GNOME) and make use of the majority language, C.
  • Graphical user applications: This is the point where a large number of programming languages ​​come into play, since it is basically the highest layer. We have a great variety: C, Python, Java, Perl and others. There are GTK +, Tcl / Tk, Qt libraries that are a graphical frontend to tasks running behind the command line.
  • The Windowsoperating system is basically made in C, C has the advantage that it can be scaled with assembler, which is a good option to optimize certain modules.

Earlier versions of Windows were made in Basic (Basic NOT visual Basic) which is a low-level language from a few years ago already. It is a language that is widely used in electronics even.

  • Currently Windows 7 Mac os x Leopard and Linuxuse more than one Technology, c # c ++ has already been used and even java, in the case of Linux, phytom c and tbn assemblers and other things are used, and Mac is always based on Unix with C ++ compilation for the latest Operating Systems.


Leave a Comment