August
1997 QUESTION 2 Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
| 2. | (a) What is the effect of adding the keyword static to a local variable in a procedure? | [2] | |
| the various retains its value between function calls, | [1] | ||
| and exists throughout the lifetime of the program execution. | [1] | ||
| (b) Given the following program: | |||
|
|||
| Result of tracing the add_val procedure: | |||
| (i) What is the output of the program when it is executed? | [4] | ||
| Result of tracing the program execution: | |||
| Value is 5 and result is 47 | [1] | ||
| Value is 1 and result is 1 | [1] | ||
| Value is 6 and result is 7 | [1] | ||
| Value is 21 and result is 28 | [1] | ||
| (ii) What would the output be if the static keyboard were removed? | [4] | ||
| Result of tracing the program when the static keyword is removed: | |||
| Value is 5 and result is 47 | [1] | ||
| Value is 1 and result is 1 | [1] | ||
| Value is 6 and result is 48 | [1] | ||
| Value is 21 and result is 63 | [1] | ||
| If the students omit the Value is . . . and result is . . ., but give the correct numerical values of value and result, award the marks as above. | |||
| (c) Trace the output produced when the following C programs are executed: | |||
| Output of two C programs: | |||
| (i) Program 1: | [4] | ||
|
|||
| x.a = 42 | [1] | ||
| x.p = 1969 | [1] | ||
| y.a = 1998 | [1] | ||
| y.p = 1998 | [1] | ||
| Award one mark for each of numbers in the output above. Do not deduct marks if the answers do not include the accompanying text such as x.a =. If the values for y.a and y.b are 1997, award on mark, instead of zero, for the two lines. | |||
| [4 marks] | |||
| (ii) Program 2: | [6] | ||
|
|||
| 77 & 42 = 8 | [1] | ||
| 77 | 42 = 111 | [1] | ||
| 77 ~ 42 = 103 | [1] | ||
| 4 << 2 = 16 | [1] | ||
| 16 >> 2 = 4 | [1] | ||
| ~(-2) = 1 | [1] | ||
| Award one mark for each line of output. Do not deduct marks if the students just list the size results without the text to the left of the =. | |||
| [6 marks] | |||