Structure of a C

The complete structure of a C program:

preprocessor statements
global declarations
User-defined functions

Preprocessor statements:

these preprocessor statements start with # and ends with .h extension, and they are not terminated by semicolons (;).these will give instructions to the compiler before compiling the programme.these are placed at the beginning of the programme.they are also called as macros. header files are also called as preprocessors .the common header file is stdio.h .this preprocessor directive is include directive .example is give below


there is another preprocessor type called as define directive.c language allows you to define certain expressions with single variable using #define.for example, the value of PI can be defined as #define PI 3.1416 .

#define PI 3.141593
int a;
printf("a=%f\n" ,PI);

global declarations:

variables or functions will be declared above main().global variables hold their values throughout whole programme. they can be used by any function or any part of the programme.the value of these global variables will differ inside the function and outside the function


int g=234;
int main ()
/* local variable declaration */
int a, b;
printf("the global variable is %d \n",g);
a = 10;
b = 20;
g = a + b;
printf ("global variable inside function is %d\n",g);
return 0;

The main() function:

main() is the main programme.this is followed by a beginning brace { and end brace } is used to mark the end of the programme.execution of every c programme starts with main().there is no c programme without main(). this main() function should be written in lowercase letters and it doesn’t end with a semi colon.


The declaration is a part of the C program where all the variables, arrays, functions etc.. used in the C program are declared and may be initialized with their basic data types. we use assign operator (=) is equal to for common declarations.


statements are called an instruction to the compiler to do some specific tasks or operations.they may be input or output statements, arithmetic, control or any other statements. They also include comments.The comments are explanatory notes on some instructions. The comment statements are not compiled and executed.


comments are used to write some notes inside the program,comments don’t include in compiling, they are not programmable statements and they are ignored by the compiler.there are two ways

1.single line : single line comments starts with // and goes end of the line,this works with only signle line ,next line will be included on the compiling

2.multi line comment: this starts with /and ends with / anything which is present in the middle of these two will be ignored.

Compiling and Executing a C program:

Compiling a C program means translating it into machine language. C compilers are used for this purpose. The C program to be compiled must be typed in using an editor. An editor is a program which allows the programmer to write the program and edit it. C compilers are available with and without editors. There are basically five steps in the successful execution of a program.

  1. Creating a source file(program file)
  2. Saving the program(with .c as extension)
  3. Compilation
  4. Linking system library functions
  5. Running(executing) the program
Structure of  in c