Top

Discussion

What is the output of this C code?

int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}

 

  • A.2   2
  • B.2
  • C.Compile time error
  • D.Depends on the compiler

Answer: D

Even though the answer is 2, this code will compile fine only with gcc. GNU C supports nesting of functions in C as a language extension where as standard C compiler doesn’t.

No comment is present. Be the first to comment.
Loading…

Post your comment