0% found this document useful (0 votes)
7 views

Structure of C Program

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

Structure of C Program

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

STRUCTURE OF C PROGRAM:

[Comment lines]

including statements

[defining statements]

void main()
{
[variable declaration section ; ]
[clear screen section ; ]
[input / output section ; ]
[processing section ; ]
[getch() ; ]
}
[functionction definitions]

comment lines :
Def: Unreadable code used in a program that is called a comment.
- It describes about the program.
- It can be used for Identification only.
- In this statement, we can use two types of symbols
/* starting comment
*/ ending comment
Any code in between these two symbols. That's called a comment.
- It can be used any where in the program.
- It can be used in any no. of times in a program.
- Nested comments are not allowed.
- Comments are splitted more than one line.
Eg.
1. /* this is single line comment */
2. /* this is
multiple line
comment */
Including statements :
Def: To down load any header files using a statement. That is called
"Including statement".
Header file:
- It is a pre-defined program.
- It contains function (Sub programs), variables and constants etc.
Syn: # include <headerfile>
Here, the symbol '#' reps. pre-processor. The word "include" is a system code.
Eg. #include <stdio.h>
Here, stdio.h is the name of header file.
If we can download this header file, we can use the pre-defined
functions and constants defined in that header file in our program.
- This statement does not ends with semicolon ( ;).
- It can be placed at the beginning of the program only.
Defining statements:
Def: To define a constant value to the var. That value does not modify through out
program.
- Generally it can be placed at the beginning of the program.
It can be used in body of the program also.
- This statement is called a 'Macro definition' or simply a 'Macro'.

Syn:. #define template expansion


Here, # pre-processor symbol
define system code

Eg. #define PI 3.143


#define P printf
#define M main( )
etc.
Note: Generally Templates can be used as Uppercase letters. Easy to identify the
templates in a program.

main() :
This is a user-defined function. Any function represents as follows,
name( )
That can do some thing in a program.
Eg. main ()
Here, the word main is followed by a pair of parentheses (). That represents a function.
- Each and Every C program must start its execution from this point only.
- This is defined by programmer only. so, it is user – defined function.
- Any function can return a value. but, main() function. does not return any value.
Because, it is preceded by the keyword 'void '.
Here, void is the one of the keyword.

Block :
More than one instruction placed in a pair of braces. That represents a block of code.
Eg. void main ( )
{
executable statements ;
----------------------------- ;
---------------------------- ;
}
variable declaration section :
- This is the first section every function definition.
- Any var. used in the function / program. That can be declared
it's data type before using it.

Syn. Datatype var1, var2, var3, ... ;

Eg. int x, data, num ;


Here, the words 'x', 'data' and 'num' are vars. of same data type int .
Each variable name separated by a comma and variable names and
data type separated by a space, ends with a semicolon.
clear screen section :
- This is the second section every function definition.
- In this section, we can use a library function.
i.e. clrscr () ;
It can clear the screen. That means, erases the previous output on the screen.
It displays empty screen.
- This function is defined in the header file, ' conio.h '.
conio.h console input output header file.
Input/output section :
In this section, we can use input instructions and output instructions.
o Input instruction : Reading any type of data from KB
(Std input device) using an instruction is called 'Input instruction '.
Eg. scanf ( ) ;
o Output instruction : Displaying any type of data on the Monitor (Std output
device) using an instruction is called 'Output instruction '.
Eg. printf ( ) ;
Here, scanf() and printf() are standard input and output instructions used in C
language. These two are library functions and defined in the header file 'stdio.h'.

processing section :
In this section, we can use arithmetic instructions and control instructions etc. This is
the body of the program.
Eg. //this is arithmetic instruction
c=a+b;
// this is control instruction
if (cond)
---------;
getch() :
- This is library function. It reads a single character. But, does not display on the
monitor.
- Generally it can be used as the last statement in every C program.
It can also use any where in the program except declaration section.
- It is defined in the header file, 'conio.h'.
- This function belongs to console input function.

You might also like