April 1999
CA208: 'C' PROGRAMMING

QUESTION 3

Total Marks: 20 Marks

Click here to access other questions

Click to access
SAMPLE STUDENT'S SOLUTIONS
for Question 3

 

(a) (i) Differentiate between the terms call by reference and call by value. [2]
(ii) Describe the relationship between pointers and arrays.

 

[2]
(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]
(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) {
   char *ptr;
   for(ptr = x; *ptr; *dst ++= *ptr++) {}
   for(ptr = y; *ptr; *dst ++= *ptr++) {}
}

 

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

void main(void) {
   int digits[5] = {54, 53, 5, 13, 17};
   int *one, *two, i;
   one = &digits[0];
   two = digits;
   *one = 72;
   *two = 68;
   printf("first = %d\tsecond = %d\n", *one,
           digits[0]);
   one = one+2;
   two = two+1;
   printf("third = %d\tfourth = %d\n", *two, *one);
   ++one;
   digits[1] = 26;
   printf("fifth = %d\n", *one);
   for(i=0; i<5; i++)
       printf("\t%d", digits[i]);
}

[10]