Basic Structure of c Program
In 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.
All C programs are having sections/parts which are mentioned below.
- Documentation section
- Link Section
- Definition section of Basic Structure of C Program
- Global declaration section
- Function prototype declaration section
- Main function
- User defined function definition section
1. Documentation section:
In 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.
The link section provides instructions to the compiler to link functions from the system library such as using the include directive.
3.Definition section of Basic Structure of C Program
The definition section defines all symbolic constants such using the #define directive.
4.Global declaration section:
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. This section also declares all the user-defined functions
5. Main () function section:
Every C program must have one main function section. This section contains two parts; declaration part and executable part.
|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.
7.User Define Function
User can define their own functions in this section which perform particular task as per the user requirement.So user create this according their needs.
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.
C programming basics & structure of C programs
Date : 28/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);
int sum (int a, int b) /* User defined function */
return a + b; /* definition section */
Enter number 1 and number 2
Sum of two numbers : 50
You can also check prime number function to understand the basic structure.
you can also check Table of a number Entered by user in c.