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;
}
Discussion:
31 comments Page 2 of 4.
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.
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.
Raghav Naganathan said:
1 decade ago
@Sagarika: It will throw an error as increment and decrement operators can't be done on an enum value.
Hope this helps.
Hope this helps.
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.
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?
Benazir said:
1 decade ago
Thanks karthiga.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers