Computer Laboratory

Supervisions 2009/2010

Supervision questions: Programming in C and C++

This is the set of questions for my supervisions in Programming in C and C++. I will typically email you a list of question numbers before each supervision, but if not, attempt the next two or three. (More questions will appear here as I set them, so come back if you want to make an early start on some of the future work.)

Administrativa & handing in work

I expect you to make a good attempt at producing solutions to the relevant questions before each supervision. I prefer submissions by email (PDF or text format). Please submit your work 24 hours before the supervision. If you want to submit a hard copy of the work to student administration, please hand it in before 17:00 two days before the supervision (i.e. before Wednesday, 17:00 for a Friday afternoon supervision) as I will have to scan it. Remember that Student Administration is closed on weekends.

When emailing me regarding supervisions, please only use my lab address, or your email will be misfiled and may slip by unnoticed:

The mark allocation (whilst very approximate) should give you a rough idea of how you should divide your time between the questions, as well as how much credit I expect a similar question to be worth in the exam. It will also serve as a guide for me when marking the questions.

Some of these questions are asking you to write code. In his case, please submit the source code and a transcript of it compiling and running, as shown in the example below:

malte@cassiopeia:~$ gcc -o foo foo.c 
malte@cassiopeia:~$ ./foo
Hello World!
malte@cassiopeia:~$ 

If there is a particular part of the course you would like explaining, or questions you have about the lectures (independent of whether they are covered by the questions or not), please let me know in an email before the supervision so that I can prepare appropriately.

Supervision 1: The C language

  1. Lecture 1, exercise 2 [2 marks]
  2. Lecture 1, exercises 3 and 4 [5+7 marks]
  3. What does the static keyword mean in
    • global context (outside a function), and
    • local context?
    [3 marks]
  4. Lecture 2, exercises 3 and 4 [4+5 marks]
  5. Why is the const keyword useful and when do we use it? [3 marks]
  6. For each of the following pointer expressions, explain what action it will perform (assume that p is a pointer to an int, q is a pointer to a char, and r is a pointer to a structure):
    • p++,
    • q--,
    • q -= *p++,
    • ++r->i,
    • r++->i,
    • *r->i,
    • *r->i++,
    • (*r->i)++,
    • *r++->i--.
    [15 marks]
  7. Lecture 3, exercise 1 [2 marks]
  8. What are the semantics of the sizeof keyword for different possible arguments (consider a local variable, a global variable and a type name)? [3 marks]
  9. Lecture 4, exercise 2 [15 marks]
  10. Optional bonus question: Describe how Duff's device (Lecture 4, slide 17) works. [5 marks]

Supervision 2: The C++ language

  1. Lecture 5, exercise 1 [15 marks]
  2. Lecture 6, exercise 1 [3 marks]
  3. Lecture 6, exercise 2 (without the division operator /) [15 marks]
  4. Lecture 6, exercise 4 [4 marks]
  5. Lecture 7, exercise 1 [10 marks]
  6. 2007 Paper 3 Question 4 [20 marks]
  7. 2007 Paper 11 Question 3, parts (c), (d) and (e) only [12 marks]