Your Ad Here

Saturday, April 19, 2008

Skeleton of a 'C' Program

C is a structured language and everything which need to be coded or programmed must be structured in nature, for those who don't know what is structured programming can follow one of the links availbale.

We will start with understanding the basic programming construct in 'C language'.

Sample Program:
#include
#include
void main()
{
printf("Hello World");
}

Point # 1:The most important thing in this program is "#include", these are called preprocessor directives in C language, it is denoted by # symbol. 'C' does not support dynamic linking, statis linking means everything which needs to be included becomes part of the executable file. So, when I wrote #include, there is a process called preprocessing which happens before compilation in 'C', it copies the content of the file specifed at the place of this statement, In our case the content of the file stdio.h will be placed in the place of #include. After the precprocessing is complete, compilation start which eventually creates the executable.

Ponit #2:
What is main() here, main is a function, a function is a small block of code which executes together. But why do we name it main?, we could have had 'small', 'big' etc. but why 'main', the answer is every function needs to be called for execution and because every application runs under the Operating System, OS is the one who starts the execution, but the OS is programmed to call only function named 'main', we can say 'main' function is the entry to the application. All other function written are called by main as and when required.

In the next post we would discuss about the standard input and output functions.

No comments: