Code Skiller logoCB Logo
Logo LearnLearnLogo PracticePracticeLogo HireHireLogo IDEIDE

Program to print “Hello World”

User image

Published by

sanya sanya

Published at: 26th Jul, 2023
1.175 mins read

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 using namespace std;’: This line is a preprocessor directive that includes the header file ‘‘. The ‘‘ header provides input/output stream functionality in C++. It allows us to use the ‘ cout’ object to print output and the ‘ cin’ object to receive input.

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