Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain the different sections in C language
C program is defined by set of protocols that are to be followed by a programmer, while writing the code.
Sections
The complete program is divided into different sections, which are as follows −
Documentation Section − Here, we can give commands about program like author name, creation or modified date. The information written in between/* */ or // is called as comment line. These lines are not considered by the compiler while executing.
Link section − In this section, header files that are required to execute the program are included.
Definition section − Here, variables are defined and initialised.
Global declaration section − In this section, global variables are defined which can be used throughout the program.
Function prototype declaration section − This section gives information like return type, parameters, names used inside the function.
Main function − The C Program will start compiling from this section. Generally, it has two major sections called as declaration and executable section.
User defined section − User can define his own functions and performs particular task as per the user’s requirement.
General form of a ‘C’ program
The general form of a C program is as follows −
/* documentation section */
preprocessor directives
global declaration
main ( ){
local declaration
executable statements
}
returntype function name (argument list){
local declaration
executable statements
}
Example
Following is the C program using function with arguments and without return value to perform addition −
#include<stdio.h>
void main(){
//Function declaration - (function has void because we are not returning any values for function)//
void sum(int,int);
//Declaring actual parameters//
int a,b;
//Reading User I/p//
printf("Enter a,b :");
scanf("%d,%d",&a,&b);
//Function calling//
sum(a,b);
}
void sum(int a, int b){//Declaring formal parameters
//Declaring variables//
int add;
//Addition operation//
add=a+b;
//Printing O/p//
printf("Addition of a and b is %d",add);
}
Output
You will see the following output −
Enter a,b :5,6 Addition of a and b is 11