Explain the Basic Structure of C Program?

If you observe a c program, you might notice that C Program can be displayed as a combination of building blocks or we can call it as functions.

A function is nothing but one or more number of statements which is created to perform a specific task.

{tocify} $title={Table of Contents}

Structure of C Program

explanation of basic structure of c program.

If you want to write a C Program, you must need to create function and put them together one after one and use them in the main function.

Generally, the structure of a C program can be viewed as shown below.

Documentation Section
Link section
Definition Section
Global Declaration section
main() Function
{
Declaration Part
Execution Part
}
subprogram section
Function 1
Function 2
.
. /*User-defined Functions*/
.
Function n{codeBox}

1. Documentation Section

Documentation Section consists of set of comment lines, a good programmer can use it for understandable, such as name of the program. This documentation Section is placed before the links section starts. Observe the example given below.

/* This is the Documentation Section */
#include <stdio.h>
#include <conio.h>{codeBox}

2. Link Section

The link section consists header files, these files can be included and it can be preprocessed before the program compiled.

This link section instructs the compiler to link the functions from the libraries. Below is the example for the link section.

#include <stdio.h>
#include <conio.h>{codeBox}

3. Defination Section

In the definition section, required symbolic constants are defined. The values of these constants can’t be changed. Here is the example for the Symbolic constants.

#define PI 3.14{codeBox}

By observing above constant, we can say that, PI is the Symbolic constant.

4. Global Declaration section

In global Declaration section, global variables are declared. We can use these declared global variables in one or more functions.

Here declared variables are also known as global variables and these declared global variables are also declared outside and above all the functions.

int a=5, b=7 ,c=8;{codeBox}

5. main() Function section

main function section consists main() function and every program must have only one main() function.

This main function consists of two sections, one is declaration section and another is executable section. These two sections can be must placed after opening brace and before closing brace.

All the variables and functions can be declared in declaration section that can be used in the executable section.

All the executable statements can be placed here. This executable section consists all instructions to be executed.

int main(){
//Statement 1
//Statement 2
.
.
//Statement n
return 0;
}{codeBox}

6. Sub program section

This is the final section in structure of a C program. This section consists all user-defined Functions that can be called by the controller in the main function

void swap(int a, int b){
int temp;
temp=a;
a=b;
b=temp;
}{codeBox}

Also Read:

Conclusion

I hope you understood the structure of C Program and this tutorial might helped you to crack your exams. If you find this tutorial helpful, please share this tutorial with your friends.

Leave a Comment