C++ «Hello World!» Program

C++ “Hello World!”  program is one of the simplest C++ programs. It displays the output “Hello World!”.

Loading…

Example: “Hello World!” Program

// A hello world program in C++
#include
using namespace std;

int main()
{
        cout 

The output of the above program is:

Hello World!

The above program includes the following:

1. // A Hello World program in C++: This section in the program includes the comment “A Hello World program in C++”. The compiler automatically ignores this type of comments but can be useful for the programmer.

2. #include: In C++, all the lines starting with # are the directives that tell the compiler to include the file inside . indicates the compiler to include input/output function in the program. It uses cin for input function and cout for output function.

3. using namespace std: The namespace includes all the elements of the standard C++ library. Here, std is the name of the namespace that tells the compiler to look for the elements like variables, functions.

4. int main(): It returns the data type integer. Every program must have a main() function. It is the head of the C++ program.

5. { and }: The opening braces ‘{‘ indicates the beginning of the main function and ‘}’ indicates the end of the main function. Everything written between these two is the body of the main function.

6. cout

7. return 0: This statement causes the main function to finish. This statement returns the value 0 from the main() function that indicates that the execution of the main() function is successful.

 

Loading...