April 2000
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)Describe the purpose of a storage class modifier in C,quoting an
example.[2 marks ]
(ii)Describe the purpose of a type modifier in C,quoting an
example.[2 marks ]

(b)(i)Give a declaration for an array of 5 integers,with all the elements initialised to 0.[2 marks ]
(ii)Declare a two dimensional array of characters,of size 2 ×2,initialised with the
values a, b, c, d [2marks ]

(c)Assuming x y and z are all declared as int state the value of z in the following
expressions,given the values of x and y
(i)z =x && y where x= 65535 and y= 0 [1mark ]
(ii)z =x && y where x= 65535 and y= 0 [1mark ]
(iii)z =x << y where x= 3 and y= 2 [1mark ]
(iv)z =x >> y where x= 3 and y= 2 [1mark ]

(d)Give the result of applying the arithmetic operators in the following expressions,
when x= 4 y= 8 and z= 12
(i)(z % x)+y [1 mark ]
(ii)(y + z)%x [1 mark ]
(iii)y* = x [1 mark ]
(iv)y* = ++x [1 mark ]

(e)Give the output of the procedure FooBar the definition of which is given below:
void foobar() {
  int *x, *y;
  int a[4]= {1, 2, 3, 4};

  x= &a[1];
  y= a;
  *(x-1)= 5;
  *y= 6;
  x++;
  y= (++y)+1;
  (*y)++;
  x= x+2;
  printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);
}
[4 marks ]

(f)Write a procedure,called CharCount the signature of which is given below,which takes in three parameters,a string s, a character c and an index i The procedure should calculate how many times c appears in s and return this value as the index i
You may not use any C library functions.
void CharCount(const char s[], const char* c, int* i); [4 marks ]

(g)Given the following definition of a simple linked list in C,define a recursive function, called search which takes three parameters,a linked list l, a value v and an index i. The function should return a reference to the the first element in the list which matches the value passed in,and the index i should indicate how many list elements have been traversed.

typedef struct node {
  struct node* next;
  int datum;
} list_element;

list_element *front, *back;
[6 marks ]