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();
return 0;
}
void foo()
{
printf("2 ");
}

 

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

Answer: B

Correct answer: Compile time error

Here the two disagree. The declaration in scope says void foo(int), so foo() is called with too few arguments; and the definition, void foo(), conflicts with it as well. Either fault alone is enough for the compiler to reject the program.

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

Post your comment

Please log in or register to post a comment.