A program is nothing but, a well-defined sequence of instructions to the machine. Such a sequence of instructions written in any of the programming languages must follow certain conventions. Here we are discussing how does the simplest version of the C program look like.
- Documentation Section
- Link Section
- Definition Section
- Global Declaration Section
- Main Function Section
Declaration Part
Executable Part
- Sub-Program Section
Function 1
Function 2
Function 3
……………………
……………………
Function n
Documentation Section
This documentation section consists of a set of comment lines giving the name of the program, the author, the date written, and the other details, which the programmer likes to use later. For example.
Program Name : Program to Calculate the TAX
Written By : Kamal B. Rana
Written Date : 01/01/2021
Updated Date : ..........
.........................
Link Section
This section provides instruction to the compiler to link the function and program codes from the system library and other files. You will know about the compiler and system library later in this tutorial. An example of this section looks like
#include <stdio.h>
#include "myfile.h"
#include "mylocalfile.c"
Definition Section
This section defines all the symbolic constants. They are the replacement of the code or value in place of some expression. For example
#define PI 3.1416
The compiler replaces all the PI that occurred in the program by 3.1416 at pre-processing time. Pre-Processing and Compiling are two different things, and we will discuss this later in this tutorial.
Global Declaration Section
The variables or anything that needs to be accessible or known to all the parts or functions of the program are declared in the global declaration section. For example
unsigned int my_variable;
The variable my_variable can be accessed from any part or function of the program because it is declared in the global declaration section. Generally, the common type of variables that has to be shared among functions is declared as global. Making a variable global must be taken carefully because it can be changed or likely changed by other parts of the program.
Main Function Section
This is the main section of the program, that the program code actually starts from this function to execute. This is the entry point of the program for execution wherever any part of the program it be. This section has two parts declaration and execution part.
- Declaration – Varaibale that are required in the main function section are declared here. A Variable is something like a container in which we can store the data used in our programs. Variables can be of any type normal variable, pointer variable, and array variables.
int variable;
float array[10];
- Execution – In this part instructions to the machine are written. They execute in the machine in the order they appear. They can process as well as input and output statements.
variable = variable + 100;
printf("Hello this is C programming tutorial");
Sub-Program Section
C programming follows structural programming meaning that a very large complex problem can be divided and solved by using smaller individual blocks called functions. Such blocks are also called subroutines or modules. So, while solving a particular program, small divided functions are written in this section, and they are called or used by the main section of the program.
int getDouble(int n){
return n * 2;
}
This section can contain multiple user-defined functions that are required/used for the program. They do nothing until and unless they are used or called in the main program.