Program to print “Hello World”
Published by
sanya sanya
Code:
#include
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
Now let's break down each line and explain its purpose:
1. ‘ #include
2. ‘using namespace std’: The objects like cin and cout are part of the ‘std’ namespace, which contains standard C++ library elements. By using this, we explicitly specify that we are using these objects from the ‘std’ namespace.
2. ‘int main() {‘: This line starts the definition of the main function, which is the entry point of a C++ program. The execution of the program begins from here.
3. ‘cout << "Hello World";’: This line uses the ‘cout’ object, which represents the standard output stream, to print the string "Hello World". The ‘<<‘ operator is used to insert the string into the output stream.
4. ‘return 0;’: This line indicates that the program has completed successfully and returns an integer value of 0 to the operating system. In C++, returning 0 from the ‘main()’ function signifies that the program executed without any errors.
When the program is executed, it will display "Hello World" on the console or terminal.
Library
WEB DEVELOPMENT
FAANG QUESTIONS