A C program is written using a basic structure that contains header files, the main() function, declarations, statements, and a return statement. Program execution normally starts from the main() function.
A C program is written using a basic structure that contains
header files, the main() function, declarations,
statements, and a return statement. Program execution normally
starts from the main() function.
A C program is like a small set of instructions: include required files → start main() → perform work → return.
| Part | Purpose | Example |
|---|---|---|
| Header File | Provides declarations for standard functions used by the program. | #include <stdio.h> |
| main() | Main function from where program execution begins. | int main() |
| Declarations | Define variables required by the program. | int a, b; |
| Statements | Perform the required operations of the program. | sum = a + b; |
| Output | Displays the result to the user. | printf() |
| return 0; | Indicates successful completion of the main function. | return 0; |
This line includes the standard input/output header file.
It provides functions such as printf() used for
displaying output.
The main() function is the main entry point of the
program. Execution begins from this function.
These statements declare two integer variables and initialize them with values.
This statement calculates the sum of the two numbers and stores
the result in the variable sum.
The printf() function displays the calculated result
on the screen.
This statement ends the main() function and indicates
successful completion of the program.
The most important part to remember is: Program execution starts from main().
| Part | Remember |
|---|---|
| #include | Includes required header files. |
| main() | Starting point of program execution. |
| Declaration | Defines required variables. |
| Statements | Perform the required operations. |
| printf() | Displays output. |
| return 0; | Ends main() successfully. |
main() function?#include <stdio.h>?printf()?return 0;?Watch a beginner-friendly explanation of the basic structure of a C program.
A short handwritten-style revision sheet for the basic C program structure will be provided here.
Use the mind map for quick revision of the main parts of a C program.