C++ First Program

In the previous chapters we have learnt the basic history and some of the reasons why C++ is not portable like C# and Java.

Sample C++ Program

/* 
This is a simple C++ program. 
Call this file Sample.cpp. 
*/  
#include <iostream>
using namespace std;  
// A C++ program begins at main(). 
int main()
{
cout << "C++ is power programming.";
return 0;
}

Output :

C++ is power programming.

Explanation : First C++ Program

Consider the following line in the programs -

/* 
This is a simple C++ program. 
Call this file Sample.cpp. 
*/
  1. It is Comment in C++ Language which is ignored by compiler
  2. Comments are written for user understanding.
#include <iostream>
  1. C++ uses different header files like C.
  2. Include statement tells compiler to include Standard Input Output Stream inside C++ program.
  3. This header is provided to user along with the compiler.
int main()
  1. Each C++ program starts with the main function like C Programming.
  2. Return type of the C++ main function is integer, whenever main function returns 0 value to operating system then program termination can be considered as smooth or proper.
  3. Whenever some error or exception occurs in the program then main function will return the non zero value to operating system.
cout << "C++ is power programming.";
  1. C++ Insertion operator (<<) is used to display value to the user on the console screen.
  2. Insertion Operator

return 0;
  1. return statement sends status report to the operating system about program execution whether program execution is proper or illegal.