main()
{
cout << "Welcome to Agricultural
university Faisalabad computer science department";
}Description with details of every thing that is used in this program.
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, in this case the system file iostream.h. The
compiler knows that it is a system file, and therefore.
looks for it
in a special place. The features of
preprocessor will be discussed later. For the time being take this line on
faith. 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.
Your program will almost certainly want to send stuff to the screen and read
things from the keyboard. iostream.h is the name of the file in which has code
to do that work for you
main() The
name main is special, in that 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("{ }"). For every open brace
there must be a matching close. Braces allows to group together pieces of a
program. The body of main is enclosed in braces. Braces are very important in
C; they enclose the blocks of the program.
cout
<< “ Welcome to agricultural
university Faisalabad computer science department”
cout:
This is
known as out put stream in C and C++. Stream is a complicated thing, you will
learn about it later. Think a stream as a door. The data is transferred through
stream, cout takes data from computer and sends it to the output. For the
moment it is a screen of the monitor. 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.
“ Welcome to
agricultural university Faisalabad”
The thing
between the double quotes (“ ”) is known as character string. In C programming
character strings are written in double quotes. Whatever is written after
<< and within quotation marks will be direct it to cout, cout will
display it on the screen.
;
There is a
semicolon (;) at the end of the above statement. This is very important. All C
statements end with semicolon (;). Missing of a semicolon (;) at the end of
statement is a syntax error and compiler will report an error during
compilation. If there is only a semicolon (;) on a line than it will be called
a null statement. i.e. it does nothing. The extra semicolons may be put at the
end but are useless and aimless. Do not put semicolon (;) at a wrong place, it
may cause a problem during the execution of the program or may cause a logical
error.
In this program we give a fixed character string
to cout and the program prints it to the screen as:


