Photo by luis gomes
This is a simple “Hello World” program. This will print “Hello World” in output screen.
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
Description
- Preprocessor Directive:
- #include
- #include is preprocessor directive. It is used to add header file in a program. Iostream is a header file that stands for input output stream. With the help of this header file we can use cin, cout statements in the C++ program.
- #include
- Namespace Declaration:
- using namespace std;
- The std namespace includes all the features of the C++ Standard Library. By including this line, we don’t need to prefix standard library names with std::.
- using namespace std;
- Main Function:
- int main() { … }
- The main function is the starting point of every C++ program. It returns an integer value, which is typically used to indicate whether the program ended successfully.
- int main() { … }
- Output Statement:
- cout << “Hello, World!” << endl;
- cout is an object of the iostream library used for outputting data to the console. Since we declared using namespace std;, we can use cout directly without the std:: prefix.
- << is the stream insertion operator, which inserts the string “Hello, World!” into the output stream.
- endl is an object of the iostream library that represents a newline character, ensuring that the output cursor moves to the next line after printing the message.
- cout << “Hello, World!” << endl;
- Return Statement:
- return 0;
- This statement ends the main function and returns the value 0 to the operating system. A return value of 0 typically indicates that the program executed successfully.
- return 0;
Leave a Reply