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:

Comment in C

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 backward 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 ".

Example of comment:

		
  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 backward slash with two asterisk 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
   

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.

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 can access the global variable.

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.

User define function

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

Post Your Comment