Comment on the output of this C code?
#include <stdio.h>
int const print()
{
printf("Sanfoundry.com");
return 0;
}
void main()
{
print();
}
Answer: B
Correct answer: Sanfoundry.com
The string is printed once and the program ends. Applying const to a function's return type qualifies the returned value; for a return type of int it has essentially no effect, since the value is a copy that the caller here discards.
It is certainly not an error - a return type may be qualified - and nothing in the code causes repetition, print() being called once from main. The trap is reading int const print() as something unusual; it is an ordinary function with a redundant qualifier.
Please log in or register to report this question.