C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 5)
What will be the output of the program ?

int main()
    enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
    printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
    return 0;
-1, 0, 1, 2, 3, 4
-1, 2, 6, 3, 4, 5
-1, 0, 6, 2, 3, 4
-1, 0, 6, 7, 8, 9
Answer: Option
No answer description is available. Let's discuss.
31 comments Page 1 of 4.

ANIL B RATHOD said:   6 months ago
Enums are always integral constants so we call enums as names of an integer value.

Enums will assign the values to its member automatically starting from 0 (zero). And next to increasing the variable, we have to increase the value explicitly.

Murthy said:   5 years ago
It's clear to understand, Thanks @Karthika.

Keerthana said:   5 years ago
By default, enum assign 0 as the starting value and successive values will be assigned for remaining members. i.e. 0 for MON, 1 for TUE, 2 for WED and so on. But if member is pre-assigned, its successive value will be assigned for next member if it is not assigned with any value. If the next member is assigned with some value then it will be considered. So in above eg, MON=-1, TUE=-1+1=0, WED=6, THU=6+1=7, FRI=7+1=8, SAT=8+1=9.

Hence the output:-1, 0, 6, 7, 8, 9.

Kamal said:   5 years ago
Yes, I agree @Karthika and @Akansha.

Karth said:   6 years ago
Yes, I agree with your concept @Karthika.

Manoja V. said:   6 years ago
Thank you @Karthika.

Ramkesh said:   6 years ago
Nice Explanation, Thank You @Ramdas.

Akanksha said:   9 years ago
Enum is short form use for Enumerated data type definition. Correct me if I m wrong.

Puneet said:   9 years ago
Enum stand for?

Sudha said:   9 years ago
I agree all the points for my friends!

Union stores in memory in same data type in same place. But continue memory allocation.

Post your comments here:

Your comments will be displayed after verification.