Discussion
Can we have enum containing enum with the same constant?
#include "stdio.h"
enum Yenum{
C, CPP, Java
};
enum Xenum{
C, CPP, Java, Yenum
};
int main()
{
enum Xenum var;
printf("%d",sizeof(var));
return 0;
}
Answer: A
Correct answer: Enum can contain enum but duplicate constants are not allowed
The two enumerations both declare C, CPP and Java, and enumerators occupy the ordinary identifier namespace at file scope - so the second set are redefinitions and the program will not compile. Naming one enumeration as a member of another is not the difficulty; the repeated constant names are.
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