Comment on the output of this C code?
int const print()
{
printf("AllIndiaExams.in");
return 0;
}
void main()
{
print();
}
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.
Please log in or register to report this question.