Sections of C Program'
Sections of C Program'
1. Documentation section
2. Preprocessor section
3. Definition section
4. Global declaration
5. Main function
Documentation section
//name of a program
Or
/*
*/
Preprocessor section
The preprocessor section contains all the header files used in a program. It informs the
system to link the header files to the system libraries. It is given by:
#include<stdio.h>
#include<conio.h>
The #include statement includes the specific file as a part of a function at the time of
the compilation. Thus, the contents of the included file are compiled along with the
function being compiled. The #include<stdio.h> consists of the contents of the
standard input output files, which contains the definition of stdin, stdout, and stderr.
Whenever the definitions stdin, stdout, and stderr are used in a function, the statement
#include<stdio.h> need to be used.
There are various header files available for different purposes. For example, # include
<math.h>. It is used for mathematical functions in a program.
Define section
The define section comprises different constants declared using the define keyword. It
is given by:
#define a = 2
Global declaration
The global section comprises of all the global declarations in the program. It is given by:
int a = 5;
char ch ='z';
char = 1 byte
float = 4 bytes
int = 4 bytes
We can also declare user defined functions in the global variable section.
Main function
main() is the first function to be executed by the computer. It is necessary for a code to
include the main(). It is like any other function available in the C library. Parenthesis ()
are used for passing parameters (if any) to a function.
1. main()
We can also use int or main with the main (). The void main() specifies that the program
will not return any value. The int main() specifies that the program can return integer
type data.
int main()
Or
void main()
Local declarations
The variable that is declared inside a given function or block refers to as local
declarations.
main()
int i = 2;
i++;
Statements
The statements refers to if, else, while, do, for, etc. used in a program within the main
function.
Expressions
An expression is a type of formula where operands are linked with each other by the use
of operators. It is given by:
a - b;
a +b;
User defined functions
The user defined functions specified the functions specified as per the requirements of
the user. For example, color(), sum(), division(), etc.
The program (basic or advance) follows the same sections as listed above.
Return function is generally the last section of a code. But, it is not necessary to include.
It is used when we want to return a value. The return function returns a value when the
return type other than the void is specified with the function.
Return type ends the execution of the function. It further returns control to the specified
calling function. It is given by:
return;
Or
return expression ;
For example,
return 0;
Examples
It is given by:
#include<stdio.h>
int main()
int a, b, sum;
// calculating sum
sum = a + b;