skip to primary navigationskip to content

Course pages 2022–23

Programming in C and C++

Assessed Exercise

The worksheet and your own personal starter pack for the Part IB C/C++ Assessed Exercise (tick) is now available.

Instructions are LINKED HERE.

Please be aware that work submitted for Assessed Exercises must be entirely your own work and that publishing or otherwise sharing answers to exercises risks you being penalised for "academic misconduct" if someone plagiarises your work.

Assessed Exercise submission deadlines are given in the Head Of Department's Notice It is important to have given in a substantially correct effort by the formal deadline, even if there are some small bits missing. You need not to have had the work marked and ticked off by the submission deadline.

Help-And-Tick Session: There has seemingly been no demand for the promised formal Help-and-Tick Session in the Intel Lab, but do email djg11 if you seek assistance over Zoom beyond what your supervisor can provide from Friday 20th January onwards.

Lecture Notes

  • Programming in C (lectures 1-9, DJ Greaves). Slides.
  • Programming in C++ (lectures 10-12, A Mycroft). Slides (alternatively 4-up)
  • This exercise sheet might prove useful for supervision questions on C and C++.
  • All Class Task Sheets (lectures 2-9). Lab Practical Exercises PDF. (These are the same as the concatenated "Session and Lab notes" below.)
  • This year's C++ videos appear on the recordings tab above; they are also available on Panopto. Unfortunately the first half of Lecture 12 is missing; this can be viewed as part of last year's videos.


  • Slide 12 of the C++ slides: line 7 in the program should cause an error as a non-const reference should not reference a temporary.
  • Slide 38 isn't very clear that "operator *" is a top-level defined function, not part of class Vector (or Matrix). We might expect that both Vector and Matrix declare as friend, so it can access both of their private members. Here is an alternative example".

Course Structure

The first 9 lecture slots are dedicated to C and the last 3 slots are dedicated to C++.

As in pre-covid days, session 1 (introduction to C) is being delivered in LT1 Pre-recorded lectures 2 to 9 should be watched in your own time. The C++ lectures, numbered 10, 11 and 12, will also be given in LT1 (but note the change of time).

The timetabled slots for sessions 2 to 9 are used for practical classes 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 above. Please ignore any remarks about the Assessed Exercise in the recorded lectures, since these may be out of date.

Exercises and per-lecture tasks and remarks

There are 8 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.

Session 2

Session 3

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 a missing extern modifer 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.
  • 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).
  • Erratum: the .h file for lab 4 should read 'extern Tree *empty;' It is never appropriate for a variable to be defined in a .h file; it should only be declared there.

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

  • There is a missing extern modifer in the graph.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.
  • 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

Supervision Work and Examples Sheet

This exercise sheet might prove useful for supervision questions on C and C++.

Installing a Virtual Machine Image

[Is this out-of-date now? Installing virtual box is almost certainly more complex than installing gcc or llvm.]

If you do not have gcc or llvm installed on your laptop, then:

  1. Download a virtual machine image for Ubuntu Linux with gcc and llvm installed.
  2. Go to the the VirtualBox website to find out how to install the VirtualBox software on your machine.