Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q12 — Programming in C

Explain with AI

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?

Choose one option
View worked solution

Answer: D

The function is declared as:

void f(int, short);

This means f accepts two arguments: the first of type int, the second of type short, and it returns void (no value).

Let's analyze the variables declared in main():

  • int i = 100; — i is of type int.
  • short s = 12; — s is of type short.
  • short *p = &s; — p is a pointer to short, so *p is of type short.

Now, let's evaluate each option:

  • Option A: f(s, *s)
    Here, s is a short variable, not a pointer. Applying the dereference operator * to a non-pointer variable (*s) is a compilation/type checking error.
  • Option B: i = f(i, s)
    The function f has a return type of void. Attempting to assign a void return value to an int variable i results in a type checking error.
  • Option C: f(i, *s)
    Similar to Option A, *s is invalid because s is not a pointer.
  • Option D: f(i, *p)
    • The first argument i is of type int, which matches the first parameter.
    • The second argument *p dereferences the pointer p (of type short*), yielding a value of type short, which matches the second parameter.
    • The function call is not assigned to any variable, which is correct since f returns void.
    This expression is completely valid and will not result in any type checking error.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions