Discussion
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.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development