Basic Structure of C Program

C Program consist of following parts:

(1) Comment

Comments are used in the program for documentation purpose. Using comment programmer can specify Logic behind the code so other programmer or user can easily understand the program.
Comments can be write anywhere in the program.
You can write comment using /* and */ symbols. Comment must always starts with /* symbol and ends with */ symbol. Anything written between these two symbol is treated as comment.
Comments written in the program are ignored by the compiler.

/* This Program finds weather given number is odd or even */

(2) Header File

C has lots of built in functions organized into various Library files (Header Files). In Order to use particular built in function we need to include particular Header file in the Program.
Particular Header file can be included in the program using #include File Inclusion directive.


stdio.h header file contains definition of various standard input output functions.

(3) Macro Substitution (Defining Constant)

Macro Substitution is used in C program to define Symbolic Constant. Symbolic Constant can be defined using #define preprocessor directive.

#define PI 3.14

It will replace all occurance of PI in the program with the value 3.14 before compiling the Program.

(4) Global Variable Declaration

Global variables are those variables that can be used by all the functions in the program. Global variables are declared outside all functions.
Sometimes it is required to share some common variables for all the user defined functions at that time they are dclared as Global in this part of Program.

(5) Main Function

main() is a starting point of C Program. C Program starts its execution from main().
Every C Program must have only one main() function as shown below:

void main()

void indicates main() function does not returns any value to operating system.
main() function contains:
 (1) Declaration of Local Variables
 (2) Declaration of User Define Functions
 (3) Satatements along with Comments
 (4) Call to User Define Functions

(6) Function Definations

User Define Functions declared inside main() function are defined after main () function.
Function Definition contains statements to be executed to perform specific task and one return statement if return type of the function is not void.

int sum(int a, int b)
  int c;
  c= a+b;
  return c;

Sample C Program

/* Simple Program to find area of circle */
#define PI 3.14
void main()
    float a,r;
    float area(float r);/* Function Declaration*/
    printf("Enter Radius:");
    a=area(r); /* Calling Function */
    printf("Area of Circle is %f",a);
    getch ();
float area(float r)
    float a;
    return a;

Download Projects

Download Programs