C Programming


This page provides content about Programming with C and version control with Git. This is the materiel used during the training week of M1 Mosig.

Lecture Slides

Programming with C

The lectures are based on the lecture slides given in CS107: Computer Organization & Systems from Standford University.

More specifically, our focus is on the following lectures:

We encourage you to also read the other lectures from that course.

Note that the slides prepared by Gregory MouniƩ are also accessible here

Version control with Git

TBD


Practical exercises

A first exercise about compiling C programs

Courtesy of Martin Quinson

Here is a first C program:

#include <stdio.h> 

int main(int argc, char** argv) {
    int answer; 3
    for (int i=0; i<5; i++) {
        printf("What is the answer?\n");
        scanf("%d", &answer);
        if (answer == 42) {
            printf("Correct answer!\n");
            exit(0); // Ends the program
        } else {
            printf("No, the answer is not %d\n", answer);
        }
    }
    printf("Sorry, you lost\n");
    return 1;
} 
$ gcc game42.c -Wall -Wextra -Werror -o game42
[Potential error messages]
$ ./game42
[The program starts executing]

Beginner level

If you are a beginner in C, we suggest to start with some of the exercises proposed on this page.

More specifically, here is the sequence of exercises that we suggest you to solve:

Medium and advanced programmers