Discussion
What is the output of this C code?
int main()
{
enum {ORANGE = 12, MANGO, BANANA = 11, APPLE};
printf("APPLE = %d\n", APPLE);
}
Answer: B
Correct answer: APPLE= 12
An enumerator without an explicit value takes the previous enumerator's value plus one, and an explicit value resets the count from that point.
So ORANGE = 12, then MANGO becomes 13, then BANANA = 11 resets the sequence, and APPLE follows at 12. Two enumerators therefore share the value 12, which C permits - enumerator values need not be distinct. The trap is expecting APPLE to continue from MANGO rather than from the explicitly reset BANANA.
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