April
1999 QUESTION 5 Total Marks: 20 Marks |
Click here to access other
questions
Click to access
|
(a) | Describe the effect of adding the keyboard static to a local variable in a
procedure or function.
|
[2] |
(b) | Identify the difference between stack and heap
allocated data in C.
|
[3] |
(c) | (i) Using a single statement, declare a one-dimensional integer array called digits, and initialise it with the values 10, 20, and 30. | [2] |
(ii) Using a single statement, declare a
two-dimensional integer array of three elements by three elements, called moredigits, and initialise it with the following
integer matrix: (9, 8, 7)(6, 5, 4)(3, 2, 1)
|
[3] | |
(iii) Using a single statement, declare a
character array called footy, and
initialise it with the letters (c, f, e, e, d, n, u, d). The array should be no larger
than is necessary to contain these letters.
|
[2] | |
(d) | The following function is intended to return an
array containing the numbers [4, 3, 2, 1]. Explain why the function may not work as
intended. int * fournums() {
|
[2] |
(e) | Assume the following definition of the function foobar: int
foobar(int xs[], int n) {
|
|
(i) Describe the result of evaluating foobar(xs, 6) when xs is the array xs[] = {-20, 11, 1, 9, -6, 5}
|
[1] | |
(ii) Describe the result of evaluating foobar(xs, 6) when xs is the array xs[] = {0, 11, 0, -5, 6, 1}
|
[1] | |
(iii) Describe the result of evaluating foobar(xs, 6) when xs is the array xs[] = {20, 11, 1, 5, 6, 1}
|
[1] | |
(iv) Describe the effect of foobar(xs, n) when given an arbitrary array xs containing n values. | [3] |