0% found this document useful (0 votes)
25 views4 pages

Structure of C

The structure of a C program typically includes header files, global declarations, a main function, and other sub-programs or functions. The main function contains the main block of statements and can declare local variables. Variables declared outside of main are global. The program flow involves getting input, performing operations, and displaying output.

Uploaded by

Aarush Pitla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Structure of C

The structure of a C program typically includes header files, global declarations, a main function, and other sub-programs or functions. The main function contains the main block of statements and can declare local variables. Variables declared outside of main are global. The program flow involves getting input, performing operations, and displaying output.

Uploaded by

Aarush Pitla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Structure of a C Program

C language does not actually follow any specific method of writing a program. It is a case sensitive language.
All the statements must be written in lower case letters (small letters). The structure of a C program is as
follows:-
Main Function Header File
<Header file> #include<stdio.h>
<Global declaration of variable> #include<conio.h>
main ( )
{ int main ( )
<local declaration of variables> { Main Block Start
---------------------------------
<statements> Function
-------------------------------- printf(“ Hello World”); and
} return 0; Statements
<sub-programs- function blocks>
} Main Block End
Comments
Structure of C
/* Structure of C*/
Header File
Global Variable #include<stdio.h>
#include<conio.h>
int a ;
Main Function main ( )
Main Block Start
{
int b, sum;
Local Variable
clrscr ( );
printf(“ \n Enter Value to A:”);
scanf(“ %d”, &a); Function
printf(“ \n Enter Value to B:”); and
scanf(“ %d”, &b);
Statements
sum = a+b;
printf(“ \n SUM = %d”, sum);
getch ( );
} Main Block End
Other Functions
• The header files or preprocessor directives give instructions to the complier to include complier
option (#include), macro substitution (#define) to substitute a constant for an identifier and
conditional (#ifdef) directives.

• The main statement block, function block and other blocks used in a C program are enclosed in
braces { }.

• Variable declared outside main ( ) are called global variables and they can be used in the main
program block and sub program block.

• Variables declared inside main ( ) are called local variables, and they are used only in block in
which they are declared. Sub program/function can also have local variables.

• Any C program has coding in the form of letters and symbols. Normally documentation to the
program is made by adding remarks or comment lines enclosed in /* and */ whenever necessary.
Output of Program
Enter Value to A: 5
Enter Value to B: 3 Input Value

SUM = 8 Output

You might also like