The GATE Grind

GATE 2016 CS – Question 22

Programming and Data Structures · Programming in C · 1 mark · Multiple choice

Consider the following C program.

void f(int, short);
void main()
{
    int i = 100;
    short s = 12;
    short *p = &s;
    __________ ;    // call to f()
}

Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?

  1. `f(s, *s)`
  2. `i = f(i, s)`
  3. `f(i, *s)`
  4. `f(i, *p)`

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) `f(i, *p)`

Explanation

`s` is a `short` and cannot be dereferenced, so `*s` in options A and C is an error. `f` returns `void`, so assigning its result to `i` in option B is an error. In option D, `i` is an `int` and `*p` is a `short`, which matches the parameters of `f`.