Ads 468x60px

Saturday 29 December 2012

Your First Program

Now you installed the compiler on your computer. Open the compiler and type the following code.
#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    cout<<"Welcome to C++\n";
    getch();
}
After typing the above code press F9 to make your executable file of your program. 
Source Code 
After pressing F9 a dialogue box will open giving you the path of your executable fill with the message that your file is up to date. 

Now press Ctrl + F9 to run your program. You will see your output. You can press any key to exit from the output screen.
Output
Now you from the above code you can see that it is started with '#' (hash). In Programming Language we do not pronounce it as hash, it is called as a preprocessor directive after that include that simply means something is going to be included and then the angle bracket (<>) starts, in the angle bracket we have to write the name of the header file which we need to include in the program.

iostream stands for input output stream, conio stands for console input output and  .h is the extension of the header file.


void main()
This is the main function of your program. The syntax of writing a function is
<return type> <function name> <simple parenthesis>
void is the return type of function main, void means the function will return nothing.
main
Every program will have a main function. The program starts from main function and in an individual program only one main can possible.
()
Simple Parenthesis, it is the syntax of writing a function as said above.
{ 

}
Now, curly bracket starts means the body of the program starts. The whole program is written under the bracket.
clrscr();
Stands for clear screen. It clears the screen from all previous output and make fresh blank screen.
cout
Stands for console out, it is the output function which will give the output of the input and will print the messages on screen.
<<
Bitwise left shift operator it is the syntax of the command cout.
" "
In double quotes we have to write the message called string.
\n
Escape sequence used for inserting new line it will not appear in the output but it will give a new line to our output.
; (semi colon)
Statement terminator,  works as full stop in programming, every statement terminates with semi colon.
getch();
A function under the header file conio.h. It reads a character from the keyboard without displaying it. It is not  really necessary in the above program but we need to put this function to see the output screen. It will hold the output screen until we don't press a key from the keyboard.

Share if you liked this Post using your favorite sharing service:

Subscribe Updates, Its FREE!

 
Related Posts Plugin for WordPress, Blogger...