Explanation of the above Program
Below is the explanation of the above program. With a description explaining the program’s meaning and use.
Sections | Description |
---|---|
/** * file: sum.c * author: you * description: program to find sum. */ |
It is the comment section and is part of the description section of the code. |
#include<stdio.h> | Header file which is used for standard input-output. This is the preprocessor section. |
#define X 20 | This is the definition section. It allows the use of constant X in the code. |
int sum(int y) | This is the Global declaration section includes the function declaration that can be used anywhere in the program. |
int main() | main() is the first function that is executed in the C program. |
{…} | These curly braces mark the beginning and end of the main function. |
printf(“Sum: %d”, sum(y)); | printf() function is used to print the sum on the screen. |
return 0; | We have used int as the return type so we have to return 0 which states that the given program is free from the error and it can be exited successfully. |
int sum(int y) { return y + X; } |
This is the subprogram section. It includes the user-defined functions that are called in the main() function. |
Steps involved in the Compilation and execution of a C program:
- Program Creation
- Compilation of the program
- Execution of the program
- The output of the program
Read more about Compiling a C Program Compilation – Behind the Scenes
Structure of the C Program
The basic structure of a C program is divided into 6 parts which makes it easy to read, modify, document, and understand in a particular format. C program must follow the below-mentioned outline in order to successfully compile and execute. Debugging is easier in a well-structured C program.
Contact Us