Monday, 28 October 2013

Remaining Part Of Lecture 3: How to Write C Program.

# include <iostream.h>
main()
{
cout << "Welcome to Virtual University of Pakistan";
}
We will look at this code line by line and try to understand them.
 >>> # include <iostream.h>
#include: This is a pre-processor directive. It is not part of our program; it is an instruction to the compiler. It tells the C compiler to include the contents of a file. You have to write this line. The sign # is known as HASH and also called SHARP.
>>> <iostream.h>
This is the name of the library definition file for all Input Output Streams.
main()
The main is actually the one which is run when your program is used. A C program is made up of a large number of functions. Each of these is given a name by the programmer and they refer to each other as the program runs. C regards the name "main" as a special case and will run this function first. If you forget to
have a main function, or mistype the name, the compiler will give you an error. Notice that there are parentheses (“( )”, normal brackets) with main. Here the parentheses
contain nothing. There may be something written inside the parentheses. It will be discussed in next lectures.
{ } Next, there is a curly bracket also called braces("{ }").
cout << “ Welcome to Virtual University of Pakistan”;
cout:
This is known as out put stream in C and C++. Hence we use cout for output.
<<
The sign << indicates the direction of data. Here it is towards cout and the function of
cout is to show data on the screen.

No comments:

Post a Comment