C Programming - SPLessons

Structure of C Program

Chapter 4

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Structure of C Program

Structure of C Program

shape Introduction

“Structure of C Program” chapter gives clear explanation of various sections of C-programs.

Any program is written and executed in various steps to give a desired output.Even if a small program is coded, it requires a structure.

shape Conceptual


shape Description

Any C program need to follow a structure which consists of certain rules. The Structure of C Program can be as follows which has various sections.Some of the sections are essential and some of them are optional.

shape Sections

Sections in Structure of C Program
Documentation Section
Link Section
Definition Section
Global Declaration Section
Main Function Section
Sub-programming Section

Documentation Section:

shape Description

Documentation section is used for giving the comments regarding the title, author,more detailed information about the program etc.

Single line comments

//sum  of two numbers

Multi-line comments

/*Welcome to SPLessons
You are reading C-programming tutorial
This program is about summing of two numbers*/


shape Description

Link section is used to link the compiler to the library function using header files.



Definition Section:

shape Description

Definition section consists of symbolic constants.


#define true 1

Global Declaration Section:

shape Description

The variables used anywhere in the program are called as global variables. In this section, global variables are declared which can be also used in user-defined functions.


int x=10;

Main Function Section:

shape Description

Main function section is the main part of the program. It mainly consists of two parts which are written between the braces {} and every line have to end with a semicolon(;).

Declaration Section: In declaration section, all the required variables are declared which can be used in the executable part.

Executable Section: In executable section, statements are given which are helpful in executing the program and giving the output.


Function 1
Function 2

Sub-Programming section:

shape Description

Sub-programming section consists of user-defined functions.These functions are called by the main function section.

shape Example

/*C basic structure example
to find sum of two numbers */	//documentation section

#include<stdio.h>		//Link section

int total;			//Global declaration section
int sum(int,int);		//Function declaration section 
void main()			//Main section
  int a,b;
  printf("\n Enter the two numbers : ");
  scanf("%d  %d",&a,&b);    /* taking two numbers as input*/
  total = sum(a,b);      /* calling function.The value returned by the function is stored in total */
  printf("\n The sum of two numbers is : %d ",total);

 int sum ( int num1,int num2)	//User defined section 
  int result;  		/* defining variable, its scope lies within function */
  result = num1 + num2 ;   /*adding two numbers*/
  return (result) ;		//definition section


Enter the two numbers : 1 2

The sum of two numbers is : 3

All the rules should be followed in every section to get a successful output from a program.


shape Key Points

  • C-Structure is built-up based on 6 sections.
  • Execution starts from main section.
  • Sub-programming section and definition sections are optional.

shape Programming

Using documentation section(comments) is the best practice because it explains the program clearly .