December 1999
CA208 : 'C' PROGRAMMING

QUESTION 1 (Compulsory)

Total Marks: 30 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 1

(a)

(i)Name two type modifiers other than unsigned .[2 marks ]

(ii)Name two storage class modifiers other than volatile .[2 marks ]

 

[4]
(b)

(i)Declare a two dimensional array of integers, called fb ,which is of size 3 ×3, and initialise it with the values 1 through to 9.[2 marks ]

(ii)Declare a dynamic array of floating point integers,called floaters ,which may have values implicitly changed and therefore should not be optimized.The size of the array should only be decided at allocation time.[2 marks ]

 

[4]
(c)

What is the result of applying the bitwise operators in the following expressions?

(i)7 & 7 [1 mark ]
(ii)7 | 7 [1 mark ]
(iii)1 » 1 [1 mark ]
(iv)1 « 1 [1 mark ]

 

[4]
(d)

Give the result of applying the arithmetic operators in the following expressions, when x =3,y =5 and z =7:

(i)(x+y*z) [1 mark ]
(ii)(x+y)%z [1 mark ]
(iii)(++x*y) [1 mark ]
(iv)(--x+ ++y) [1 mark ]

 

[4]
(e)

Given the following definition of the procedure foobar :

void foobar(int state,int timeout){
  switch(state){
  case 1:
    if(timeout <0 ){
      printf("Suspend task;");
      break;
    }
  case 2:
    printf("Running task;");
    break;
  default:
    printf("Halt task;");
  case 3:
    printf("Delete task;");
  }    
}      

Trace the following calls and produce their output:

(i)foobar(1,-1);[1 mark ]
(ii)foobar(1,0);[1 mark ]
(iii)foobar(3,0);[1 mark ]
(iv)foobar(5,0);[1 mark ]

 

[4]
(f)

Write a procedure,called Exchange ,the signature of which is given below,which takes in three integer parameters,x ,y and z by reference.On exit,the value of z should be equal to the sum of the other two parameters,and the other two parameters should be exchanged.

void Exchange(int*x,int*y,int*z);

 

[4]
(g)

A Fibonacci sequence is a sequence of numbers where the next number in the sequence is calculated by the sum of the previous two numbers.For example,a sequence which started with the numbers (1,2)would have as its third entry 3 (calculated by 1+2).The next number would be 5 (calculated by 2+3)and so on.

Write an iterative procedure,called Fibonacci ,the signature of which is given below, which takes three parameters,x ,y and z .The procedure should use x and y as the initial two entries in the sequence,and print out the next z entries.

void Fibonacci(int x,int y,int z);

[6]