...

/

Anatomy of a "Hello World!" Program

Anatomy of a "Hello World!" Program

Practice with the "Hello World!" program in C++.

“Hello World!” program

Here is the source code for a program that prints “Hello World!” on the screen. Look at the program, and then we will discuss every component of the program in detail.

Run the code below and see the output!

Press + to interact
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}

Explanation

When we run the code above, it prints “Hello World!” on the screen. This means that we can modify the code given above to print anything on the screen. Sounds interesting!

But first, let’s understand the meaning of each line in a “Hello World!” program.

Preprocessor directives

Line No. 1: Lines that start with # are known as preprocessor directives. Preprocessor directives tell the compiler to preprocess some information before starting the compilation. The Header file contains the declarations of predefined functions in C++.

#include is a preprocessor directive. It tells the preprocessor to add the content of the ...