C Programming is a Structured programming language. it allows writing programs in small modules. and because C follows a structure it is easy to debugging, testing and maintenance.

Basic Structure of C Program




Structure of a C Program



C PROGRAM STRUCTURE
Include Header File Section
Global Declaration Section
main()                          
{                                  
Declaration Part
Execution Part
}                                 
User-defined Functions
{                               
Statements
}                                

Include Header File Section

Every C program has some header files that are used for function definition that is used in the program. in c programming, each header file is by default extended with .h extension. header files are files that have defined some functions in them that we can use in our program. and in the header file section, we include the necessary header files.

Global Declaration

In the global declaration section, we can define some variables that are used by more than one function. and it is a must that all the variables should declare outside of all the functions. and these variables are known as global variables.

Main Function

In c programming, every program must have a main() function. because the main() function is a starting point of every C program. and the execution of the program always begins with the open curly bracket of the main() function.

Declaration Part

The declaration part declares the entire variables that are used in the executable part. means we set some values to the variables that are used in the program.

Executable Part

The execution part contains the statements that need to execute. it contains a set of statements or a single statement. and all these statements are enclosed between the braces of the main function.

User-Defined Function

In the user-defined section, the user defines some functions for doing some tasks. and generally, this section would be defined after the main() function.


Steps For Executing The Program


Generally in C programming, the execution of a program is done in three steps.
  1. Creation of program
  2. Compilation of a program
  3. Execution of the program

Creation of program

To create a c program we can use C editor or any online editor. after creating a program we can save with the .c extension. by default file extension is .c but it is not necessary to save the file with the .c extension.

Compilation of a program

To convert a c program from human language to machine language we need a compiler. and the conversion of code from human language to machine language is called compilation. and this part is done after all the statements get correct. if there is no error in the program then the machine code of the program is stored in another file with the same name and .obj extension.

Execution of the program

After the successful creation of the .obj file and generation of machine code. the whole machine code is loaded into the computer's main memory and the program is executed.