December
1998 QUESTION 1 (Compulsory) Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS
|
(a) | Name two type modifiers other than unsigned. | [2] |
Any two of the
following: signed, long or short.
|
||
(b) | Name two storage class modifiers other than static. | [2] |
Any two of the
following: extern, auto, register, const, or
volatile.
|
||
(c) | Describe what a structure and a union are, and identify the difference between the two. | [3] |
A structure is an
ordered fixed size sequence of named objects (1 mark). A union is an overlapping sequence
of named objects (1 mark). The difference between the two is the size of a structure is
the sum of the sizes of its constituent parts, and the size of a union is the size of the
largest part (1 mark).
|
||
(d) | Create appropriate declarations for each of the following variables: | |
(i) digits, an array of 10 unsigned integers. | [1] | |
unsigned int
digits[10];
|
||
(ii) apc, an array of 20 pointers to characters. | [1] | |
char *apc[20]; or char
*(apc[20]); Note: the [] have higher precedence
that *, so in the absence of parentheses, the array descriptor is applied first, then the
pointer descriptor.
|
||
(iii) pacc, a pointer to an array of 20 characters. | [2] | |
char (*pacc)[20]; or
char pacc[][20];
|
||
(e) | Write a procedure maxpair that takes two integer valued parameters x and y as its arguments. The effect of the procedure should be to change the values of x and y so that x holds the larger of the two values, and y the smaller. | [4] |
Two definitions of the maxpair procedure
are shown below: void
maxpair(int *x, int *y) { if (*x < *y) { void maxpair(int *x, int *y) { if (*y > *x)
{ and the following marking scheme should be used:
|
||
(f) | Trace the following code segment and produce the
output: void main(void) { one = &num_list[1]; one = one + 3; for(i=0; i<5; i++)
printf("%d ", num_list[i]);
|
[5] |
One mark for the correct
numbers appearing on each line below: First = 2 Do not deduct marks for incorrect typesetting of the answer. i.e., if the second answer is written as Second = 66 instead of Second = 66, then marks should still be awarded. |
||