(2): Tuesday 22nd September:
Imperative programming, operations, errors.
JCB went through the material in the slides, and there were
a good few questions. Some worth noting:
- Which variables appear in hello.c? Answer: none.
main is not a variable, because you can't change
the function while the program is running. More confusingly,
EXIT_SUCCESS is not a variable - it could be, but
it so happens that it isn't: if you write EXIT_SUCCESS =
42; you will get an error. We'll discuss that in more
detail later in the course.
- For the top of slide 11, we discussed evaluation in
the context of "8*8". We noted that inside the command shown
below, that the second parameter (the 8*8 that is not inside the
quotes) will be evaluated to 64 before it is piped
into the %d inside the output string. So the function
printf("8*8 is %d", 8*8);
will generate the following output:
8*8 is 64
- Next we considered the issue of variables in C, and we
showed how we could assign values to variables. We used
the analogy of a variable being like a "blackboard" (or a
"slate") where we can write a single value (and change it later
whenever we want).
We mentioned that in assigning values to variables,
that the rule is that the right-hand-side (of the = sign)
first gets its value evaluated and after that the
value gets placed into the variable named on the left (of
- We talked about the need to declare a variable (with
its particular type) before using it.
We finished the lecture by discussing some common errors
that arise when debugging/running code.
Assigned reading: Nothing today. But this was an oversight
on my part - relevant sections of "A Book on C" are 1.1, 1.2, 1.3, 1.5
and 1.6, and these should all be read.