Loading...
C

Structure Of a C Program

Every C program and its statements must be in a particular structure. The general structure of a C program is given below.

             Documentation Section

             Link Section (or) Preprocessor Directive Section

             Global Declaration Section

              int main (void)      [Main Section]

                  {

                        Local Declarations

                        Executable Part

                        ————————–

                   }

              User Defined Function Section

1.Documentation section :[They are ignored by the compiler]

This section is used to provide small description of the program. The comment lines are simply ignored by the compiler that means they are not executed .In C, there are two types of comments. 

       1. Single Line Comments: Single line comment begins with ‘//’symbol. We can write any number of single line comments.

       2.Multiple Lines Comments: Multiple lines comment begins with ‘/*‘symbol and ends with ‘*/‘ . We can write any number of multiple lines comments in a program.

In a C program, the comment lines are optional. Based on the requirements, we write the comments. All the comment lines in a C program just provide the guide lines to understand the program and its code. 

2. Preprocessor directive section:

Preprocessing command are used to include header files and to define constants. We use ‘#include‘ statement to include header file into our program. We use ‘#define‘ statement to define a constant. The preprocessing statements are used according to the requirement.

3. Global declaration section:

Global declaration section is used to define the global variables. There are some variables that are used in more than one function. Such variable 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.

4.main() function section:

Every C program must have one main function section. This statement (main) specifies the starting point of the C program execution. This section contains two parts; declaration part and executable part.

Declaration part: The declaration part part declares all the variables used in the execution part.

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 braces ({) and the ends at the closing braces (}). The closing brace of the main function is the logical end of the program. All statements in the declaration and executable part end with a semicolon.

5.Subprogram section:

If the program is a multi-function program then the subprogram section contains all the user-defined functions that are the main() function. User-defined functions are generally placed immediately after the main() function, although they may appear in any orde.

Example:

/* C basic structure program Documentation Section */

#include<stdio.h>     /*Link Section*/

int main()                   /*Main Section*/

{

   printf(“WELCOME TO ‘C’ LANGUAGE”);

    return 0;

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *