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

Discussion

Comment on the output of this C code?

int const print()
{
printf("AllIndiaExams.in");
return 0;
}
void main()
{
print();
}

 

  • A.AllIndiaExams.in is printed infinite number of times
  • B.AllIndiaExams.in
  • C.Runtime Error
  • D.complilation error

Answer: B

Correct answer: AllIndiaExams.in

The program prints the string once and stops. Applying const to a function's return type simply qualifies the value returned; for a return type of int it has no practical effect at all, since the returned value is a copy that the caller here discards.

Nothing in the code causes repetition - print() is called once from main and returns 0. The trap is reading int const print() as something exotic; it is an ordinary function with a redundant qualifier.

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

Post your comment

Please log in or register to post a comment.