December 1999
CA208 : 'C' PROGRAMMING

QUESTION 5

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 5

(a)

Given the following definition of the function foobar :

int foo(int a [ ],int b)
{
int i;
  for(i= 0;(i < b) && (a [ i ]<0);i ++) { }
  return ((i >= b) ? (-1) : i);
}  

 

(i)Describe the effect of calling the function foo with an arbitrary array a containing b values.[3marks ]


(ii)Rewrite the function foo using a while loop.[3marks ]

 

[6]
(b)

Write a function,called last ,the signature of which is given below,which takes an integer parameter x .The procedure should simply return the value which was passed in as a parameter the previous time it was called,or 0 if it is called for the first time.

int last(int x);

 

[4]
(c)

Write a procedure,called minmax ,the signature of which is given below,which takes three arguments:w ,an integer array,x ,which is an integer specifying the size of the array,and y and z which are pointers to integers.On exit,y should point to the smallest value in the array,and z should point to the largest.The array x should remain unchanged.

void minmax(int w [ ], int x , int* y , int* z);

[5]