skip to primary navigationskip to content

Course pages 2023–24

Programming in C and C++

Course Structure

There are 12 slots timetabled for this course. The first 9 slots are dedicated to C and the last 3 slots are dedicated to C++.

As in pre-covid days, slot 1 is a lecture (introduction to C) delivered in LT1. The pre-recorded lectures for slots 2 to 9 should be watched in your own time. The C++ lectures, numbered 10, 11 and 12, will also be given in LT1.

The timetabled slots for sessions 2 to 9 are used for practical lab sessions in the Intel Lab where DJG will be available. Outside of those slots, please consult your supervisor. Each of the eight practical classes has a task to complete, but these are not assessed in any way, so please feel free to collaborate as much as you want, but don't just hand out your own answer.

Practical assessment for this course will be via the formal written Assessed Exercise and subsequent viva voce session. The details will be below. Please ignore any remarks about the Assessed Exercise in the recorded lectures, since these may be out of date.

As stated above, the 8 practical lab sessions are not assessed: it is recommended to attened, but this is in no way compulsorary.

Assessed Exercise (Tick)

There is one Assessed Exercise for this course.

Here is the worksheet ProgC-exercise2324.pdf.

Your personal starter pack HERE.

For those called to Viva Voce or seeking assistance where their supervisor cannot help, please follow the viva slot announcements on VIVA DATES.

Primary Materials

Note: this year the C and C++ lecture notes are combined into this single PDF file.

Supervision Work and Examples Sheet

This exercise sheet might prove useful for supervision questions regarding C.

C++ supervision exercises are at the end of the printed lecture notes.

Lab Programmng Tasks and per-lecture tasks and remarks

There are 8 Lab programming tasks in C and one C/C++ Assessed Exercise

  • These programming tasks are informal and not ticked. You may collaborate with others on these as much as you like.
  • On the other hand, the Assessed Exercise must be your own work and its details will be announced at the top of this page in due course.

Session 1

There is no specific task 1, except to gain access to a C compiler and repeat one of the demos from lecture 1. For example


int main()
  printf("Hello World!\n");
  return 0;

Try also the demo from Concurrent Systems L1:

Session 2

Session 3

  • Task 3 Lab notes (PDF)
  • Task 3 Lab package (.tar.gz format)
  • Of interest?: Dr Bjarne Stroustrup (creator of C++), when reading for his PhD at the Computer Laboratory, shared an office with Prof. Sir Andy Hopper (frwho was PhD supervisor to Dr David J Greaves (lecturer of this course)).

Session 4

Note: The video and slides for Lecture 4 may mention a previous year's Assessed Exercise (tick). This is not quite the same as this year's tick.

  • There is/was a missing extern modifier in the Tree.h file, causing `empty' to be both declared and defined. It is never good style to define variables in a .h file. Please insert extern if you had a problem - I thought this was fixed and now I've fixed it again.
  • Task 4 Lab notes (PDF)
  • Task 4 Lab package (.tar.gz format)
  • Of interest?: The BCPL language often ran on word-addressed machines, so the normal pointer de-referencing operator (asterisk in C, pling (exclamation mark) in BCPL) could not fetch individual bytes in memory (as needed for character strings) and hence a separate operator was provided in BCPL (using the percent sign).

Session 5

  • Task 5 Lab notes (PDF)
  • Task 5 Lab package (.tar.gz format)
  • Of interest?: Prof Alan Mycroft (lecturer of this course), together with Dr Arthur Norman (of the Computer Laboratory) and others, wrote the first C compiler for the Arm processor (which runs the apps in every mobile phone).

Session 6

  • Task 6 Lab notes (PDF)
  • Task 6 Lab package (.tar.gz format)
  • Of interest?: Prof David J Wheeler (PhD examiner to Dr David J Greaves (lecturer of this course)) invented the subroutine (today often called a method or function). The machine instruction to call a subroutine (which saves the address of the following instruction) was first called the Wheeler Jump. But now it is often called call (sic).

Session 7 (String Matching)

  • Erratum (on video?): The arguments to set_left where we are making a loop should be n1 instead of node1, etc..
  • Task 7 Lab notes (PDF)
  • Task 7 Lab package (.tar.gz format)
  • Of interest?: The C-- backend language is a C-like programming language whose creators include Dr S Peyton-Jones of the Computer Laboratory. It is intended to be generated mainly by compilers for very high-level languages rather than written by human programmers. Unlike many other intermediate languages, its representation is plain ASCII text, not bytecode or another binary format.

Session 8 (Caches)

  • Task 8 Lab notes (PDF)
  • Task 8 Lab package (.tar.gz format)
  • Of interest?: In 1999, Dr David J Greaves (lecturer of this course), wrote a program that converted Verilog to C++. Hundreds of chip companies used this program to generate fast software models of ICs that did not yet exist. When a whole chip was converted, the output was sometimes a C++ program of millions of lines in length. It consisted mainly of one basic block (per clock domain) containing straight-line code. Such blocks were called once per modelled clock cycle and as a result, there was no temporal locality in the instruction caches. This degraded performance, but the tool was still useful. GNU gcc handled the generated code with no problem. Special adaption was required to overcome Visual C's limitations such as parenthesis nesting of greater than 255 levels or structs with thousands of fields.

Session 9

Secondary Materials

Last year’s course materials are still available.