Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this C code?

void foo();
int main()
{
void foo(int);
foo(1);
return 0;
}
void foo(int i)
{
printf("2 ");
}

 

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

Answer: A

Correct answer: 2

The declaration inside main - void foo(int) - is the one in scope at the call, so foo(1) matches it, and it agrees with the definition. The outer void foo() declares a function with an unspecified parameter list rather than none, so it does not conflict. The program prints 2.

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

Post your comment

Please log in or register to post a comment.