Uninitialized variables should never be assumed to have a ‘default’ value. The only reason that your first example looks correct is because the underlying data type is integer which typically defaults to a value of 0, but you should never assume that this will always be the case.
Okay @cgales , but even when i try to display the the enum in string format why i getting first value of enum as a output . In code 1– outputs : Default value of enum variable = 0
Name = A
In your both of your examples, the variable ‘state’ is uninitialized which shouldn’t be the case. Since the underlying data type is ‘int’, it will typically be initialized to 0, but you should never assume that it will always be 0.
With the value 0, your first example prints the string name associated with the enum value 0, or ‘A’.
Your second example displays an empty string since the value 0 isn’t associated with any enum value.