C Programming - Structures, Unions, Enums - Discussion

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

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
Explanation:
No answer description is available. Let's discuss.
Discussion:
31 comments Page 2 of 4.

Sudha said:   1 decade ago
I agree all the points for my friends!

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

Agana said:   1 decade ago
enum takes the size of int values.

Gaurav shukla said:   1 decade ago
What is type of data member in enum?

Sahiti said:   1 decade ago
enum takes the size of int i.e 2 bytes.

Keerthi said:   1 decade ago
What is the size of enum?

Rahul said:   1 decade ago
@Lakshmi : enum assigns value to its member's sequentially.
It will assign 0 to first member if value is not predefined.
Here MON= -1 so TUE becomes 0 WED would have become 1 but.
WED=6 is given so TUE=7 FRI=8 SAT=9.

Chandresh said:   2 decades ago
This is because enum assigns to it's variable component sequential integer values.

Sagarika said:   1 decade ago
If there is ++mon intsead of mon, then what will be the output?

Raviraj BK said:   1 decade ago
enum variables are assigned with consective inegers.
ie if mon =-1 then tue will be assigned with o ie next vale of -1.
this is method of assignment in enum datatype.

Sega said:   1 decade ago
What about enum size in the memory?


Post your comments here:

Your comments will be displayed after verification.