SyntaxStudy
Sign Up
C The Structure of a C Program
C Beginner 1 min read

The Structure of a C Program

Every C program follows a predictable structure. At the top you place preprocessor directives such as `#include` to pull in library headers. Below those come global declarations and function prototypes. The special `main()` function is the entry point the operating system calls when your program starts. All other functions are called directly or indirectly from `main()`. Statements in C are terminated with semicolons, and blocks of statements are grouped with curly braces. C is case-sensitive, so `Main` and `main` are different identifiers. Comments can span multiple lines with `/* ... */` or cover a single line with `//` (introduced in C99). Keeping your code well-commented and consistently indented is essential as programs grow in size. C's standard library, accessed through headers like ``, ``, and ``, provides a rich set of functions for I/O, memory management, and string manipulation. You do not need to write everything from scratch; learning which library functions are available and when to use them is an important part of becoming proficient in C.
Example
/*
 * structure.c — anatomy of a well-structured C file.
 */
#include <stdio.h>    /* printf, scanf                */
#include <stdlib.h>   /* EXIT_SUCCESS, EXIT_FAILURE   */

/* --- Constants defined at the top --- */
#define MAX_ITEMS 100
#define PROGRAM_VERSION "1.0"

/* --- Function prototype (declaration before use) --- */
void print_banner(const char *version);

/* --- main: program entry point --- */
int main(void)
{
    print_banner(PROGRAM_VERSION);

    int count = 0;
    printf("Enter a number (0 to quit):\n");

    while (scanf("%d", &count) == 1 && count != 0) {
        printf("You entered: %d\n", count);
    }

    return EXIT_SUCCESS;
}

/* --- Function definition --- */
void print_banner(const char *version)
{
    printf("=== My C Program v%s ===\n", version);
}