...

/

Hello World!

Hello World!

Learn the basic syntax of C++ in detail.

Let's revisit the "Hello World!" program from our previous lesson. We'll break it down and discuss each line in detail, step by step!

Press + to interact
//This program displays “Hello World!” on the screen
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}

Feel free to experiment with the code in the above widget.

Adding comments

C++ provides its users with the ability to write pointers in the code in the form of comments. Comments serve as a helper to coders so they can understand the code once they revisit the code. To add a comment in the code, add // double frontslash before the comment. In the code we have:

Press + to interact
//This program displays “Hello World!” on the screen

You can also also add a multi-line comment in the code using /* */ and add the comment between the lines. You can test multi-line comment here:

Press + to interact
#include <iostream>
using namespace std;
// beginning of our main function
int main() {
/*
- This code is used to print Hello World!
- We use the cout statement for that
*/
cout << "Hello World!";
return 0;
}

The #include statement

It is written as:

Press + to interact
#include <iostream>

The hash sign (#) signifies the start of a preprocessor commandIn C++, preprocessor commands tell the preprocessor to do things like include files, compile code conditionally, define macros, and manage lines of code before the code is actually compiled.. The #include command is a specific preprocessor command that effectively copies and pastes the entire text of the ...