skip to primary navigationskip to content

Department of Computer Science and Technology



Course pages 2023–24

Programming in C and C++

Principal lecturer: Dr David Greaves
Taken by: Part IB CST
Term: Michaelmas
Hours: 12
Format: In-person lectures
Suggested hours of supervisions: 3
Exam: Paper 4 Question 5, 6
Past exam questions, Moodle, timetable


This course aims

  • to provide a solid introduction to programming in C and to provide an overview of the principles and constraints that affect the way in which the C programming language has been designed and is used;
  • to introduce the key additional features of C++.



  1. Introduction to the C language. Background and goals of C. Types, expressions, control flow and strings.
  2. (continued) Functions. Multiple compilation units. Scope. Segments. Incremental compilation. Preprocessor.
  3. (continued) Pointers and pointer arithmetic. Function pointers. Structures and Unions.
  4. (continued) Const and volatile qualifiers. Typedefs. Standard input/output. Heap allocation. Miscellaneous Features, Hints and Tips.
  5. C semantics and tools. Undefined vs implementation-defined behaviour. Buffer and integer overflows. ASan, MSan, UBsan, Valgrind checkers.
  6. Memory allocation, data structures and aliasing. Malloc/free, tree and DAG examples and their deallocation using a memory arena.
  7. Further memory management. Reference Counting and Garbage Collection
  8. Memory hierarchy and cache optimization. Data structure layouts. Intrusive lists. Array-of-structs vs struct-of-arrays representations. Loop blocking.
  9. Debugging. Using print statements, assertions and an interactive debugger. Unit testing and regression.
  10. Introduction to C++. Goals of C++. Differences between C and C++. References versus pointers. Overloaded functions.
  11. Objects in C++. Classes and structs. Destructors. Resource Acquisition is Initialisation. Operator overloading. Virtual functions. Casts. Multiple inheritance. Virtual base classes.
  12. Other C++ concepts. Templates and meta-programming.


At the end of the course students should

  • be able to read and write C programs;
  • understand the interaction between C programs and the host operating system;
  • be familiar with the structure of C program execution in machine memory;
  • understand the potential dangers of writing programs in C;
  • understand the object model and main additional features of C++.

Recommended reading

* Kernighan, B.W. and Ritchie, D.M. (1988). The C programming language. Prentice Hall (2nd ed.).