April
1999 QUESTION 3 Total Marks: 20 Marks |
Click here to access other
questions
GRADE A
|
(a) | (i) Differentiate between the terms call by reference and call by value. | [2] |
(ii) Describe the relationship between pointers and arrays. | [2] | |
(i) In call by
reference, the formal parameter using this scheme in a function/procedure will retain any
changes to its value throughout the parameter lifetime in the program, even if it has
exited the function/procedure. In constrast, by using call by value, the value of the parameter( if there are any changes) will only be retained in the lifetime of the function or procedure. (ii) An array can be declared as a pointer to the first element of the array. However, a pointer may not be an array.
|
||
(b) | Write a procedure which takes two arguments - sum and product - such that the value of sum on exit is equal to the sum of the two values on entry, and the value of product on exit is equal to the product of the two values on entry. | [4] |
void operation (int
*sum, int *product) { int *temp; temp=sum; *sum +=*product; *product = *product * *temp; return; }
|
||
(c) | Describe the effect on the following function on
the argument dst, if x and y are null terminated strings, and dst is a sufficiently large character
array. void strfun(char *dst, char *x, char
*y) { |
[2] |
This function copies
string x and string y into string dst, such that dst will contain string x followed by
string y on exit.
|
||
(d) | Trace the following code segment and write down
the output produced: void main(void) { |
[10] |
first =
68 second = 68 third = 53 fourth = 5 fifth = 13 68 26 5 13 17 |