C++ First Hello World Program with Explanation

In this programming tutorials, we will see our very first Hello World Program in C++ and understand line by line what it means in a very simple and overview level.

Run Online

Now lets try to understand this code line by line –

  1. // my first program :  This line is a comment line. Comments are extra details about the code and have no actual effect on the program logic or execution. They are only meant for programmers to write notes about their code. Any line beginning with ‘//’ without quotes OR in between /*…*/ in C++ is comment.
  2. #include <iostream> :  In C++, all lines that start with pound (#) sign are called directives and are processed by preprocessor which is a program invoked by the compiler. The #include directive tells the compiler to include a file and #include<iostream>It tells the compiler to include the standard iostream file which contains declarations of all the standard input/output library functions which we need to take input from user and print output to the console.
  3. int main() : This line is used to declare a function named “main” which returns data of integer type. A function is a group of statements clubbed together under a single name used to perform certain task or activity. the main() function in C++ is a special function as it is the starting point of the program execution. Execution of every C++ program begins with the main() function, no matter where the function is located in the program. So, every C++ program must have a main() function.
  4. { and } : The opening braces ‘{‘ indicates the beginning of the main function and the closing braces ‘}’ indicates the ending of the main function. Every thing between these two comprises the body of the main function.
  5. cout << “Hello World”; : This line tells the compiler to display the message “Hello Worlld” on the screen. This line is called a statement in C++. Every statement is meant to perform some task. A semi-colon ‘;’ is used to end a statement. Semi-colon character at the end of statement is used to indicate that the statement is ending there. The cout is used to identify the standard character output device which is usually the desktop screen. Every thing followed by the character “<<” is displayed to the output device.
  6. return 0; : This is also a statement. This statement is used to return a value from a function and indicates the finishing of a function. This statement is basically used in functions to return the results of the operations performed by a function.

So thats it for this tutorial guys, I have a YouTube video tutorial for the same so you can check that youtube video too if you want a video lecture for the same –

Leave a Reply

Your email address will not be published. Required fields are marked *