Skip to content
UPEEC

Structure of a C Program

Headers, the main function, statements and return codes — the anatomy of a C program.

Beginner
Comments 0
#include <stdio.h>          // preprocessor: include a header

int main(void) {            // execution starts here
    printf("Hello, UPEEC!\n");
    return 0;               // 0 = success
}

Every statement ends with ;, blocks use { }, and comments are // ... or /* ... */. Larger programs split code into .c files with matching .h headers that declare functions.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.