Structure of C Program

The structure of C program implies the composition of a program, i.e. it answers questions such as “what are the main components to write a C program? How are they organized?”

basic structure of c program

1. Documentation Section

This section contains a set of comment lines giving the name of program, the author, algorithms, methods used and other details. This will be useful in future for users and developing teams. The documentation acts as a communication medium between members of development team when a number of developers are working in the same project. It is used by maintenance engineers to update and upgrade the system in future. While debugging and testing the program it plays a specific role as it acts as user manual. 

For example, the title of a program can be written in this section as,
/* This program displays natural numbers from 1 to 10 */
Note: /* … */ denotes comments in C.

2. Link Section

Link section provides data to link functions with program from the system library through compiler. For example, the statement.

#include links input/output functions like printf() and scanf() with the program. 

This section is also called the header declaration section. We include a set of header files in which several built-in functions are defined in the libraries under these header files.

3. Definition Section

In this section, all symbolic constant are defined. Symbolic constant are discussed in later chapters.

4. Global Declaration Section

The variables which are used in more than one function or block are called global variables. These variables are defined or declared in this section. It is also used to declares all the user-defined functions. To inform the compiler about the name of function it generally declared to User-defined functions and programmer’s functions , its return types (if any) and the data types of the function arguments (if any) used.

This type of function declaration is called function prototyping.

5. main() Function Section 

Every C program starts with a main() function, there are declaration and executable parts. The declaration part declares all the variables used in the execution part.

For example, declarations can be done as,

int n1, 

int n2 = 5;

The execution part has executable operation like,

n1 = n1 + 1;
n2 = n1 * 5;

6. Subprogram Section

This section contains all the user-defined functions that are called in the main function. All the sections except the main() function section may be absent when they are not required. 

These are demonstrated in the examples below.

#include <stdio.h>

int main() {
   /* C program to display Welcome to C programming World !!! */
   printf("Welcome to C Programming World !!!");

   return 0;
}

Output

Welcome to C Programming World !!!


0 Like 0 Dislike 0 Comment Share

Leave a comment