Program Structure :

/* Comments */

Comments are a way of explaining what makes a program. Comments are ignored by the compiler and used by others to understand the code.

#include<iostream>

C++ Header Files - this is a preprocessor directive. It tells the preprocessor to include the contents of iostream header file in the program before compilation. This file is required for input output statements.

int/void main()

int/void is a return value, which will be explained in a while.

main()

The main() is the main function where program execution begins. Every C++ program should contain only one main function.

return 0;

The return instruction makes the main() to finish and it returns a value, in this case it is returning 0.

First look at C++ Program :

Simple example of a C++ program that prints a string on the screen.

Example :

  1. /* Author: techbaz.org
  2. Date: 2018-11-07
  3. Description: "Welcome to C++ Program!" on the screen */
  4. #include<iostream>
  5. int main()
  6. {
  7. std::cout<<"Welcome to C++ Programming.";
  8. return 0;
  9. }

Output :

C++ language Program Welcome to C++ on the screen

namespace :

If you specify using namespace std then you don’t have to put std:: throughout your code. The program will know to look in the std library to find the object. Namespace std contains all the classes, objects and functions of the standard C++ library.

Example :

  1. /* Author: techbaz.org
  2. Date: 2018-11-07
  3. Description: "Welcome to C++ Program!" using namespace std */
  4. #include<iostream>
  5. using namespace std;
  6. int main()
  7. {
  8. cout<<"Welcome to C++ Programming.";
  9. cout<<endl<<"Its very easy";
  10. return 0;
  11. }

Output :

C++ language Program Welcome to C++ on the screen using namespace std

Note : endl among other things, will flush the stream.


Next Update

Loading...

We adding new programming language tutorials very soon.

We make a Collaboration with HackIsOn YouTube Channel So, Please Subscribe Their Channel and keep supporting