Home  >  Article  >  Backend Development  >  Explain the different parts of C language

Explain the different parts of C language

PHPz
PHPzforward
2023-08-26 19:09:06885browse

Explain the different parts of C language

C programs are defined by a set of protocols that programmers must follow when writing code.

Parts

The complete program is divided into different parts as follows:

  • Documentation Section - here , we can give commands about the program, such as author name, creation or modification date. The information written between /* */ or // is called a comment line. These lines are not considered by the compiler during execution.

  • Link section - In this section, the header files required to execute the program are included.

  • Definition Section - Here, variables are defined and initialized.

  • Global declaration section - In this section, global variables that can be used throughout the program are defined.

  • Function prototype declaration section - This section provides information such as the return type of the function, parameters, and names used internally by the function.

  • Main function - The C program will be compiled starting from this part. Usually, it has two main parts called declaration part and executable part.

  • User-Defined Section - Users can define their own functions and perform specific tasks according to the user's needs.

The general form of 'C' program

The general form of 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

The following is a C program that performs addition using a function with parameters but no return value−

Online demonstration

#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

The above is the detailed content of Explain the different parts of C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete