Structure of C Program

In this section you will learn Structure of C Program. How is C program look like? There are total 5 section of C program. You will learn basic skeleton of C program or you can say basic things of C program.

Total 5 section are there:

1. Comment

C program contain group of statement. All statement execute in program but some of the statement not execute. That are called comment statement. Comment are the C program statement which will not execute. We can also say it None-Executable statement.

Why we make comment?

Why we make comment in program that question come in beginner programmer mind. Basically comment are used to provide the some useful information or some small documentation about the program. Most of the time we use comment statement in large program.

What is the advantage of Comment?

How many types comment are there in C.?

In C language we have two types comments.

Example of Single Line Comment:

To make the single line comment we use two backword slash (//) symbol. This is called single line comment statement. In this program we are giving the information about the program by comment section. Comment section never will execute.

Now see the program code. By comment we are giving the information about the program logic. Like we are printing the value of variable a.

    void main()
    {
      int a=10;
      clrscr();
      
      //printing the value of variable a.
      
      printf("Value of A is: %d",a);
      getch();
    }

Output:


	Value of A is: 10

Example of Multiline Comment:

To make the Multiline comment we use two backword slash with two astric symbol (/* */). This is called multiline comment statement. In this program we are giving the information about the program by comment section. Comment section never will execute.

Now in this program code we are making multiline comment by giving more information.

    void main()
    {
      int a=10;
      clrscr();
      
      /*printing the value of a variable by
      taking single variable. this is our simple
      program of C.*/
      
      printf("Value of A is: %d",a);
      getch();
    }

Output:


	Value of A is: 10

2. Pre-processor Directives

hash (#) symbol is called pre-processor and include called directives. Both together called pre-processor directives.

	
    #include
    

Both together also called file inclusion macro. Macro are nothing but a peace of code or block of code, which use to execute the peace of code or block of code before the main function using pre-processor directives.

Header file which end with (.h) extension and which contains predefine function declaration.

Example of header files:


	#include(stdio.h);
    

	#include(conio.h);
    

#define is another pre-processor directives to create the own macro's or peace of code.

3. Global Declaration

In C we have two type's declaration. Declaring a variable or a function called declaration.

Local Declaration

Declaring a variable inside the function or within the block called local declaration. Whose scope is within the function.

Example of Local Declaration:

	
    fun()
    {
    int a = 10;
    printf(" %d ",a);
    }
    
    fun1()
    {
    
    }

In above example fun1() cannot access the variable a because the scope of variable is within the block or within the function.

Global Declaration

Declaring a variable outside the function called global declaration. Whose scope is outside the function and inside the function.

Example of Global Declaration:

	
    int a = 10;
    fun()
    {
    
    }
    
    fun1()
    {
    
    }

In above example variable a declared as a global variable and both function access the global variable.

4. main function

Every program will have main function. main function is the entry point of the program execution. When we execute the program compiler first execute the main function.

5. User define function

User define function also called subroutine function. It is define by the user. 1, 2, 3 section are optional.

Advertisement here

Share this Page.

Post Your Comment