Department of Computer Science and Technology

Course pages 2018–19

Programming in C and C++

Principal lecturers: Dr Neel Krishnaswami, Prof Alan Mycroft
Taken by: Part IB CST 50%, Part IB CST 75%
Past exam questions

No. of lectures: 12
Suggested hours of supervisions: 3
Prerequisite courses: None, though Operating Systems would be helpful.

Aims

The aims of this course are 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, including the differences betweeen it and C++.

Lectures

  • Introduction to the C language. Background and goals of C. Types and variables. Expressions and statements. Functions. Multiple compilation units. Tooling for C programming. [2 lectures]

  • Further C concepts. Preprocessor. Pointers and pointer arithmetic. Data structures. Dynamic memory management. Examples. [2 lectures]

  • Memory Management Unique ownership. Object graphs and graph traversals. Aliasing and deallocation. Mark and sweep algorithms. Reference counting. Arenas. Stack allocation. Handles and compaction. [3 lectures]

  • Memory Hierarchy and Cache Optimization Cache hierarchy. Data structure layouts. Intrusive lists. Array-of-structs vs struct-of-array representations. [1 lecture]

  • Linkers, loaders and debugging. Executable sections. Debug symbols. Inspecting program state. [1 lecture]

  • C semantics. Undefined vs implementation-defined behaviour. Common optimisation problems. Buffer and integer overflows. Examples. [1 lecture]

  • Introduction to C++. Goals of C++. Differences between C and C++. References versus pointers. Overloading functions. [1 lecture]

  • Objects in C++ Classes and structs. Exceptions. Destructors. Operator overloading. Virtual functions. Casting. Multiple inheritance. Virtual base classes. Templates and meta-programming. [1 lecture]

Objectives

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 main differences between C and C++.

Recommended reading

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