Pages

Thursday, 3 January 2013

To Explain The C Program

To explain the program:

1) main ():

          main () is a collective name given to a set of statements. This name has to be main (), it can not be any thing else. All statements that belongs to main () are enclosed with a pair of braces { } as shown below.

 main()
{
  statement 1;
  statement 2;
}

Technically speaking main () is a function has a pair of parentheses () associated with it.

2) printf ():

       It is also a function. It has divided in to two parts.Its is used for output purpose to print some thing on the screen.
     printf( "sting",variable list);
                part 1       part 2


part 1 :

    In part one we use the following 
1) Escape sequences.
2) Format specifier.
3) Literal  
4)  Field width.

Now we discuss only 1 and 2.


1) Escape sequences :

 1) \n It is used for one line break or new line.
 2) \b It is used for bake space.
 3) \f It is used for form feed.
 4) \\ It is used for backslash.
 5) \t It is used for tab.
 6) \r It is used for carriage return.
 7) \a It is used for alert beep.

2) Format Specifier :

    There are many format specifier but now we can discuss only three type of format specifier.

 1) %d it is used for integer specification.
 2) %f it is used for float or real specification.
 3) %c it is used for character specification.

Part 2:

     In part 2 we enter variable names etc.

What is scanf(): 

     scanf is an input statement. it is used to get value at the run time of a program .

For example:

 main()
{
int a;
printf(" enter value");
scanf(" %d",&a);
}

In the above example we see that scanf () function has two parts in first part we give format specifier and in the second part we give variable name.

Note:

   Put ampersand (&) before the variable in the scanf function must because & is an address operator.
It gives the location number used by the variable in memory.


No comments:

Post a Comment