CITS2002 Systems Programming  
next CITS2002 CITS2002 schedule  

The structure of C programs

Let's looks at the high-level structure of a short C program, rotate.c (using ellipsis to omit some statements for now).
At this stage it's not important what the program is supposed to do.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

/* Compile this program with:
   cc -std=c99 -Wall -Werror -pedantic -o rotate rotate.c

#define ROT 13

static char rotate(char c)
    return c;

int main(int argcount, char *argvalue[])
    // check the number of arguments
    if(argcount != 2) {
    else {
    return 0;

Of note in this example:

  • Characters such as a space, tab, or newline, may appear almost anywhere - they are stripped out and ignored by the C compiler.

    We use such whitespace characters to provide a layout to our programs. While the exact layout is not important, using a consistent layout is very good practice.

  • Keywords, in bold, mean very specific things to the C compiler.

  • Lines commencing with a '#' in blue are processed by a separate program, named the C preprocessor.

    In practice, our program is provided as input to the preprocessor, and the preprocessor's output is given to the C compiler.

  • Lines in green are comments. They are ignored by the C compiler, and may contain (almost) any characters.

    C99 provides two types of comments -

    1. /* block comments */  and
    2. // comments to the end of a line


CITS2002 Systems Programming, Lecture 2, p1, 2nd August 2019.