C++ “Hello World!” Program

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

Example: “Hello World!” Program

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<iostream>: In C++, all the lines starting with # are the directives that tell the compiler to include the file inside <>. <iostream> 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<< “Hello World!”: The cout is the function that displays the output in the screen. Everything inside the ” ” is displayed on the screen. In this program, the compiler prints the output Hello World! as shown above.

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.


SHARE C++ “Hello World!” Program

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *