GATE 2016 CS – Question 22
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?
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`.