- 3

What is the output of this code? enum Test {a=2,b,c,d,e}; static void main (string [] args){int(x) = (int)Test.c ; writeln (x)}

answer that came up was 4 how??

7th Jun 2017, 11:50 PM
thomo
thomo - avatar
4 Answers
+ 3
It would be error, those parenthesis when creating the int are not valid. Anywho, for enums they start at the value of 0 by default, each increasing by one. So: enum Test{ a, b, c, } Is the same as writing: enum Test{ a = 0, b = 1, c = 2 } If you modify the default value, everything after that will keep incrementing as usual. So: enum Test{ a = 2, b, c } Is really the same as: enum Test{ a = 2, b = 3, c = 4 } So, the c is 4.
8th Jun 2017, 12:04 AM
Rrestoring faith
Rrestoring faith - avatar
- 2
c is 4
14th Sep 2018, 9:13 AM
KRISHNA VENI S CSE
KRISHNA VENI S CSE - avatar
- 2
Answer 4
28th Mar 2019, 5:02 AM
Sridhar Raj.P
Sridhar Raj.P - avatar
- 2
answer: 4
10th Jan 2020, 7:12 AM
Đào Ngọc Tuáș„n Anh
Đào Ngọc Tuáș„n Anh - avatar