Home Tutorials C Tutorial Structure of a C Program
Structure of a C Program

Structure of a C Program


A basic C program is organized into logical sections: documentation, header inclusion, definitions, global declarations, the main() function, and user-defined functions.

// Documentation: My first structured program
#include <stdio.h>  // Header inclusion

#define PI 3.14       // Definitions

int add(int a, int b); // Function Declaration

int main() {
    int result = add(5, 3);
    printf("Sum = %d\n", result);
    return 0;
}

int add(int a, int b) { // User-defined function
    return a + b;
}

Simplified Breakdown

  • Header Files: These bring ready-made features (like printf) into your program.
  • #define: Used to create constants (like PI) that stay the same throughout the program.
  • Function Declarations: These act as a "heads-up" to the compiler that a specific function exists.
  • The main() Function: The heart of the program; this is where execution starts.
  • User-Defined Functions: These help divide complex work into small, reusable blocks.
Example

🏋️ Test Yourself With Exercises

Take our quiz on Structure of a C Program to test your knowledge.

Browse Quizzes »