Structure of C program
The format of writing C program is
called structure. The basic structure of C language program is very flexible.
It increases the power of the language. It consists of followings parts.
·
Preprocessor
Directive
·
Main()
Function
·
Program
body
. CommentsPreprocessor Directive
Preprocessor directive is an
instruction given to the compiler before the execution
of actual program.
Preprocessor directive is also known
as compiler directive.
We write all preprocessor directives
before Main Function (void main)
The semicolon ( ; ) is not used at
the end of preprocessor directives.
Preprocessor directive start with
hash sign ( # ).
Types of preprocessor directive:-
Mostly two preprocessor directives
use in C-Language.
Include
Preprocessor Directive
Define Preprocessor Directive
Include Preprocessor Directive
It is used to include header filer in
a program for different purpose.
Syntax
#include<header_file_name
.h>
Example
#include<stdio.h>
#include<conio.h>
Define Preprocessor Directive
It is used to store constants in
program. We use those constant anywhere in program.
Syntax
#define identifier value
Example
#define pi 3.1415
#define e 2.81
Header Files
Headers File is collection of pre
define functions to perform different tasks.
Many Header files can be include in one program. The extension of header
file is .h.
Syntax
#includes<header_file_name> .
h>
Example
#include<stdio.h>
#include<conio.h>
#include<math.h> etc
· Main
Function:-
Every C program start with main
function.
Every C program must contain main
function. If a program does not contain
main function , it can be compiled but cannot be executed.
Every statements can be written in
the body of the main() function
Syntax
Void main ()
{
Body of main function
}
· C statement:-
The statements of the program are written in curly braces { } .The curly brace {is called opening brace / starting delimiter and the curly brace is called
closing brace / ending delimiter.
The braces are also known as delimiters.
Each statement in C language is terminated by semicolon (;).
Example:-
#include<Stdio.h>
#include<conio.h>
{
clrscr ();
printf("IT is My First
Program");
getch();
}
Comments
Comments are like helping text in
your C program and that are ignored by compiler. It is start with /* sign and
end with */ sign.