+ 1

Can anyone help me with with this enumerations..

enum{ MANGO=5, BANANA=4, PEACH }; printf("%d",peach); Options are given below.. A) 3 B) 0 C) compilation error D) 5

14th Apr 2019, 3:40 AM
Dheeraj
Dheeraj - avatar
9 Answers
+ 6
Each value in an enum is the value of the preceding element + 1. If you don't assign any values to the elements, they are numbered starting from 0: enum { A, B, C = 5, D, E = 14 }; Here, A will be 0, B will be 1, C will be 5, D will be 6 and E will be 14
14th Apr 2019, 5:04 AM
Anna
Anna - avatar
+ 3
Naveen Maurya is right but if you had used Peach in the print the answer would be 5 as it immediately follows Banana in the enumeration which has a value of 4.
14th Apr 2019, 4:05 AM
Sonic
Sonic - avatar
+ 3
Thanks Anna..i got it..😊😊
14th Apr 2019, 5:06 AM
Dheeraj
Dheeraj - avatar
+ 1
I guess it leads to an error (C) as enumerations should be case-sensitive.
14th Apr 2019, 3:56 AM
Naveen Maurya
Naveen Maurya - avatar
+ 1
Sonic, is that true? I did not know that.
14th Apr 2019, 4:07 AM
Naveen Maurya
Naveen Maurya - avatar
+ 1
Yep..Am sorry guys ... They're all in upper case...
14th Apr 2019, 4:34 AM
Dheeraj
Dheeraj - avatar
+ 1
Sonic,yep ur answer is correct. Can u explain in detail...please... As peach is not assigned to any value,it should return an error.. isn't it ...
14th Apr 2019, 4:36 AM
Dheeraj
Dheeraj - avatar
0
Still a compilation error since you cannot use a ; inside an enum
14th Apr 2019, 4:39 AM
Anna
Anna - avatar
0
Anna,now it's correct..what about the explanation of output..
14th Apr 2019, 5:01 AM
Dheeraj
Dheeraj - avatar