What is the output of the below program?
#include<stdio.h> enum batch1 {Arun, Mani, Purna}; enum batch2 {Sujatha, Aparna, Mani}; void main() { unsigned int var1; for(var1 = Arun; var1 <= Purna; var1++) { printf("%d ", var1); } }
------------------------------------------
The above program tests two scenarios:
1. enum declaration
2. enum initialization
2. enum initialization
----------------------------------------------
when an enum is declared, the integer identifiers are assigned values starting from 0.
If we see batch1 enum, Arun = 0, Mani = 1, Purna = 2 are the values assigned to integer identifiers.
Similarly, for batch2 enum, Sujatha = 0, Aparna = 1, Mani = 2 is the assignment.
If we see batch1 enum, Arun = 0, Mani = 1, Purna = 2 are the values assigned to integer identifiers.
Similarly, for batch2 enum, Sujatha = 0, Aparna = 1, Mani = 2 is the assignment.
In the for loop, when the var1 = Arun is checked initially, it meant var1 = 0 and similarly for other conditions in the for loop.
When Mani is encountered in the loop, Mani is an integer identifier in two enum and the values are different.
Both the enum are in the same scope of the program. so, the compiler throws an error.
0 Comments