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. */
- It is Comment in C++ Language which is ignored by compiler
- Comments are written for user understanding.
#include <iostream>
- C++ uses different header files like C.
- Include statement tells compiler to include Standard Input Output Stream inside C++ program.
- This header is provided to user along with the compiler.
int main()
- Each C++ program starts with the main function like C Programming.
- 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.
- 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.";
- C++ Insertion operator (<<) is used to display value to the user on the console screen.
return 0;
- return statement sends status report to the operating system about program execution whether program execution is proper or illegal.