Wednesday, 6 January 2016

Structure of C program

/* This program prints Hello World on screen */

-----------------------------
#include <stdio.h>
Void main()
{
   printf(''Hello World\n'');
}
-----------------------------

Structure of C program



  •  /* This program ... */

The symbols /* and */ used for comment. This Comments are ignored by the compiler, and are used to provide useful information about program to humans who use it.


  • #include<stdio.h>


This is a pre-processor command which tells compiler to include stdio.h file.


  •  main()


C programs consist of one or more functions. There must be one and only one function called main. The brackets following the word main indicate that it is a function and not a variable.


  • { }


braces surround the body of the function, which may have one or more instructions/statements.


  • printf()


it is a library function that is used to print data on the user screen.


  • ''Hello World\n'' 


It is a string that will be displayed on user screen \n is the newline character.


  • ;

 A semicolon ends a statement.


  • return 0;

 return the value zero to the Operating system.


C is case sensitive language, so the names of the functions must be typed in lower case as above.

we can use white spaces, tabs & new line characters to make our code easy to read. 

No comments:

Post a Comment