April 1999
CA208: 'C' PROGRAMMING

QUESTION 1

Total Marks: 20 Marks

Click here to access other questions

Click to access
SAMPLE STUDENT'S SOLUTIONS
for Question 1

 

(a) Name two type modifiers other than signed.

 

[2]
(b) Name two storage class modifiers other than const.

 

[2]
(c) Create appropriate declarations for each of the following variables:
(i) digits, an array of 15 short integers. [1]
(ii) decimals, an array of 5 floats which may have their value implicitly changed, and therefore should not be optimized. [1]
(iii) apc, an array of 20 pointers to characters.

 

[1]
(d) Trace the following code segment and write down the output produced:

void main(void) {
   printf("6&3 = %d\n", 6&3 );
   printf("6&&3 = %d\n", 6&&3 );
   printf("6|3 = %d\n", 6|3 );
   printf("6||3 = %d\n", 6||3 );
}

 

[4]
(e) Trace the following code segment and write down the output produced:

void main(void) {
   int a = 5;
   int b = 2;
   int c = 1;

   printf("b+c*a = %d\n", b+c*a);
   printf("(b+c)*a = %d\n", (b+c)*a);
   printf("++b +c*a = %d\n", ++b +c*a);
   printf("(b++ +c)*a = %d\n", (b++ +c)*a);

}

 

[4]
(f) Informatics requires a function which will calculate the average mark for a group of students in an exam. Marks are all whole numbers in the range 0..60, and are stored in integer arrays.

Write a function, which builds on the prototype given below, which takes two parameters - the integer array and a specifier representing the size of an array - and will return the average mark of all those stored in the array. Note that although the marks which are passed into the array are all whole numbers, this will not necessarily be the case for the average.

    double averageMark(int marks[], int size);

[5]