Discussion
What will be the output of the following C code?
#include <stdio.h>
enum hi{a,b,c};
enum hello{c,d,e};
main()
{
enum hi h;
h=b;
printf("%d",h);
return 0;
}
Answer: C
Correct answer: Error
Both enumerations declare an enumerator called c, and enumerators share the ordinary identifier namespace at file scope - so the second declaration is a redefinition and the compiler rejects it. Unlike structure tags, enumerators are not scoped to their own type in C. (C++'s enum class was introduced to fix exactly this.)
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