Lets print “Hello CPP” as the first CPP program and than understand it in detail.
#include <iostream.h> #include<conio.h> void main() { clrscr(); cout <<"Hello CPP!"; getch(); } |
Output
Hello CPP! |
Description:
#include <iostream.h> :
“#include” is a preprocessor directive used to include a library file in the code. The header file “iostream.h” is included in the source code to use the pre-defined functions “cin” and “cout”.
#include <conio.h>: The header file “conio.h” is included in the source code to use the pre-defined functions “getch”.
void main() :
Void represents the data type of the main function which is a must for every C program.
{} :
{} represents the opening and closing of the main function.
cout<<“Hello C!”; :
The cout function outputs the string on the console screen.
getch():
The getch() function is used to block the screen till any key is pressed. It simply asks for a single character.
Compilation and Execution:
Click on Compile menu and then on Run menu or click ctrl+F9 directly, both for compile and run.