Saturday, August 20, 2011

Syntax of C program !

In the previous post we have seen introduction of C and its advantage,now we will see how to write a simple C program or know how is simple syntax of C program.First of all we must know that a program consist of one or more functions,functions are nothing other than group of statements which are executed together so that program can perform specified task.The main( ) function is one of the important function in C programming , as execution of each and every C program starts with main( ) function.So now we will see a simple and most famous example of C program from which every programmer had started its programming i.e printing "Hello World" on screen.

# include<stdio.h>
   main( )
{
    printf("Hello World");
}

In above program  #include directive tells the preprocessor to treat the contents of specified files as if those contents had appeared in the source program at the point where directive appears.
"stdio.h" is standard input output library and always written inside "< >" i.e. <stdio.h>
printf( ) is the command which can be used to print what user wants, it prints exactly matter which is inserted into " " . i.e in above example printf(" Hello World") .Whose output is Hello World.
Always remember to end every statement in C program with " ; " semi colon or you will get syntax error.
Also every function( ) opens with "{" bracket and ends with "}" .
So now you can try your first program in C.

No comments:

Post a Comment