Basic Structure of C ProgramIn this article, you will learn about basic structure of C program. C program consists of different function here we will define necessary function that are needed in basic structure of c program. Sections of the C Program
1. Documentation sectionIn the basic structure of c program 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. 2. Preprocessor SectionAll the header files of the c program are declared in the preprocessor section of the program. Header files access the library codes that are necessory for our program. Multiple files is inserted into program before the process compilation. Example:
3. Definition sectionThe definition section defines all symbolic constants such using the #define directive. Example:
|
A. Declaration part: | The declaration part declares all the variables used in the executable part. |
B. 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 closing brace of the main function is the logical end of the program. All statements in the declaration and executable pas semicolon. |
If the program is a multi-function program then the subprogram section contains all the user-defined functions that are called in the main () function. User-defined functions are generally placed immediately after the main () function, although they may appear in any order.All above section of basic structure of c program are very important to understand so keep focus firstly on these basic sections.
Example:
void main()
or
int main()
Below C program is a very simple and basic program in C programming language. This C program displays “The sum of Two integer numbers given by the user, user entered numbers in main function and call the user defined function and user defined function return the answer after processing.
C language is case sensitive so each statement should be ended with semicolon (;) which is a statement terminator.
/*
Documentation section
C programming basics & structure of C programs
Author: envirementalb.com
Date : 28/09/17
Update:29/09/17
*/
#include <stdio.h> /* Link section */
int total = 0; /* Global declaration, definition section */
int sum (int, int); /* Function declaration section */
int main () /* Main function */
{
int a,b,total; /*Local variable declaration*/
printf (“Enter number1 and number2”); /*output function*/
scanf(“%d %d”,&a,&b); /*input function*/
total = sum (a,b); /*function call */
printf (“Sum of two numbers : %d \n”, total);
getch();
}
int sum (int a, int b) /* User defined function */
{
return a + b; /* definition section */
}
Output
Output Will according to the input numbers