Hola mundo en lenguaje C++

Author
By Darío Rivera
Posted On in Lenguaje C++

In our previous post on Introduction to the C++ language, we saw the main features, advantages and disadvantages of this wonderful language. Today, we will roll up our sleeves and write our first program in C++, the classic Hello world!.

Here is our first program in C++.

// Hello world in C++ language

#include <iostream>

int main() {
   std::cout << "Hello world in C++!";
   return(0);
}

The first thing to review in this program are the comments marked with //. Everything that comes after these characters will be ignored by the compiler. The next thing to highlight is the inclusion of a header file.

#include <iostream.h>

This instruction is a type of pre-compiled instruction. It indicates to the compiler that it should add the code from the iostream file. All the instructions from the preprocessor are preceded by the # character. The previous instruction adds what is called a header file.

After this we find the declaration of the main() function. Every C++ program must have a main function as it is the starting point of the program. The content or body of the function is delimited by the { } characters. This function must return zero if everything goes as expected.

Finally, the main content of the body of the main function is the cout instruction. This function sends the text enclosed in quotes to the standard output, in this case, it prints it to the console. This function has also been previously prototyped in the iostream.h file and that is why we have included it.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.