Structure of C Program
- Get link
- X
- Other Apps
STRUCTURE OF C PROGRAM
C Program has following sections:
In these section, we can write details about program and programmer. Like - program title, user/student name, roll no, semester etc... These details can we given in comments. Comments can be given in two ways:
A. Single Line Comment: We can give comment in single line using //.
Ex. //WAP to find percentage.
B. Multiple Line Comment: Multiple lines comment can we give using /* ------------*/.
Ex. /* Program title: WAP to find percentage.
Student name: Ram
semester: 1/A */
2. LINK SECTION:
- In this section, we include system libraries or header files.
- Source code or definition code of system defined function are written in system libraries.
3. DEFINITION SECTION:
- In this section, we can define constants.
- Constants means those variable which have fixed value throughout the program.
- Example:
- #define pi 3.14
- #define size 80
4. GLOBAL DECLARATION SECTION:
- In this section, we declare global variables and user defined functions.
- Global variable are those variables which we can use anywhere in the program
- User defined function is created by user to perform specific task.
- Example:
- void add(); // declaration of user defined function.
- int a,b,c; // declaration of global variables.
5. MAIN FUNCTION SECTION:
- Void main() is a user defined function.
- Execution of program starts from void main() function.
- Void main() function starts with { and ends with }.
- It has two parts:
1. Variable Declaration
2. Executable Part
1.Variable Declaration: We can declare all variables in this section.
2.Executable Part: We can write source code of program in this section.
Example:
void main()
{
int a,b,c; <---- variable declaration
--------
-------- <-----Executable code
--------
}
6. SUB PROGRAM SECTION:
- In this section, we write definition code of all user defined functions.
- When program is divided into sub tasks, each task is know as user defined function.
- Example:
Void main()
{
------
-----
-----
}
void add()
{
-----
-----
}
- Get link
- X
- Other Apps
Comments
Post a Comment