Chapter 1 Elementary Programming
The structure of a simple program :
Documentation Section | ||
Link Section | ||
Definition Section | ||
Global Declaration Section | ||
main() | Function Section | |
{ | ||
Declaration Part | ||
Executable Part | ||
} | ||
Subprogram function | ||
function1 | (User define function) | |
function2 | ||
..... | ||
functionn |
The documentation section consists of a set of comment lines giving the name of the program, the author and other details which the programmer would like to use later. | |
The link section provides instruction to the compiler to link function from the system library. | |
The definition section defines all symbolic constants. | |
There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all the functions. | |
Every C program must have one main() function. This section contains two parts, declaration part and executable part. The declaration parts declares all the variables used in the executable part. There is at least one statement in the executable part. These two parts must appear between the opening and closing braces. The program execution begins at the opening brace and ends at the closing brace. | |
The subprogram section contains all the user-defined functions that are called in the main function. | |
All section, except main function section may be absent when they are not required. |
Example :
#include <stdio.h>
main()
{
printf(" Welcome to C programming \n");
}
#include <stdio.h>
main()
{
printf(" Welcome to C programming \n");
}
Output :
Welcome to C programming