Home > Backend Development > C++ > body text

Explain the different parts of C language

PHPz
Release: 2023-08-26 19:09:06
forward
900 people have browsed it

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
}
Copy after login

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);
}
Copy after login

Output

You will see the following output−

Enter a,b :5,6
Addition of a and b is 11
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!