GATE | GATE-CS-2016 (Set 1) | 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?
(A) f(s, *s)
(B) i = f(i,s)
(C) f(i,*s)
(D) f(i,*p)
Answer: (D)
Explanation: i is integer and *p is value of a pointer to short.
1) Option 1 is wrong because we are passing “*S” as second argument check that S is not a pointer variable .So error
2) Second option is we are trying to store the value of f(i,s) into i but look at the function definition outside main it has no return type. It is simply void so that assignment is wrong. So error
3) Option 3 is wrong because of the same reason why option 1 is wrong
4) So option d is correct.




Please Login to comment...