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!
//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:
//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:
#include <iostream>using namespace std;// beginning of our main functionint 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:
#include <iostream>
The hash sign (#) signifies the start of a #include
command is a specific preprocessor command that effectively copies and pastes the entire text of the ...