devnotes.

Anatomy of a C Program

Every C program has the same basic skeleton, built from a small set of required pieces.

#include <stdio.h>          // preprocessor directive: pulls in printf's declaration

int main(void) {            // program execution always starts in main
    int age = 20;            // a statement, ending in a semicolon
    printf("Age: %d\n", age); // function call
    return 0;                // exits main, 0 conventionally means "success"
}

#include <stdio.h> is a preprocessor directive — processed before real compilation begins — that copies in declarations from the C Standard Library's I/O header, which is why printf is available. int main(void) is the required entry point of every C program; the operating system calls this function to start execution, and void explicitly says main takes no arguments (as opposed to the int argc, char *argv[] form used to read command-line arguments).

Every statement ends with a semicolon, and related statements are grouped into blocks with {} — a function body is simply a block. return 0; ends main and hands an exit status back to the operating system; by long-standing convention, 0 means the program finished successfully, and any non-zero value signals an error.

Anatomy of a C Program: Structure Explained | DevNotes