C Programming • C Basics, Operators, Loops
C Programming / Basic C program structure

Basic C program structure

Notes 2 C Basics, Operators, Loops

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.

Notes

Basic C Program Structure

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.

💡 In Simple Words

A C program is like a small set of instructions: include required files → start main() → perform work → return.

Basic Structure of a C Program

#include <stdio.h> int main() { // declarations // statements return 0; }

Parts of a C Program

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;

Example: Add Two Numbers

#include <stdio.h> int main() { int a = 10; int b = 15; int sum = a + b; printf("Sum = %d", sum); return 0; }

Understanding the Program

1. #include <stdio.h>

This line includes the standard input/output header file. It provides functions such as printf() used for displaying output.

2. int main()

The main() function is the main entry point of the program. Execution begins from this function.

3. int a = 10; and int b = 15;

These statements declare two integer variables and initialize them with values.

4. int sum = a + b;

This statement calculates the sum of the two numbers and stores the result in the variable sum.

5. printf("Sum = %d", sum);

The printf() function displays the calculated result on the screen.

6. return 0;

This statement ends the main() function and indicates successful completion of the program.

Program Flow

Header File ↓ main() ↓ Variable Declarations ↓ Processing / Statements ↓ Output ↓ return 0 ↓ Program Ends
📌 Remember

The most important part to remember is: Program execution starts from main().

Quick Revision

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.

Important Exam Questions

Short Answer Questions

  1. What is the basic structure of a C program?
  2. What is the purpose of the main() function?
  3. What is the use of #include <stdio.h>?
  4. What is the purpose of printf()?
  5. What is the use of return 0;?

Long Answer Questions

  1. Explain the basic structure of a C program with a suitable example.
  2. Write a C program to add two numbers and explain each part of the program.
  3. Explain the role of header files, main(), statements and return statement in a C program.
🎥 Recommended Learning

Watch a beginner-friendly explanation of the basic structure of a C program.

▶ Watch: Basic C Program Structure — Hindi

📝 Handwritten Notes

A short handwritten-style revision sheet for the basic C program structure will be provided here.

🧠 Mind Map

Use the mind map for quick revision of the main parts of a C program.