potato
potato

Reputation: 4589

enum datatype default number assignment

to what numbers (if any) do Jan, Feb, Mar map if I just write code like this:

enum months {Jan, Feb, Mar}; 

but not explicitly give them corresponding numbers like in this case:

enum months {Jan=1, Feb, Mar};

Upvotes: 0

Views: 45

Answers (1)

kmcnamee
kmcnamee

Reputation: 5265

By default, the first element in a list is set equal to 0, and each subsequent element is assigned a value one greater. Therefore in your first:

enum months {Jan, Feb, Mar};

Jan = 0, Feb = 1, Mar = 2

In your second:

enum months {Jan=1, Feb, Mar};

Jan=1, Feb = 2, Mar = 3

Reference 1

Reference 2

Upvotes: 1

Related Questions