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 1 of 4.
Chandresh said:
2 decades ago
This is because enum assigns to it's variable component sequential integer values.
Lakshmi said:
1 decade ago
Please can you explain me in brief.
Karthika said:
1 decade ago
enum days={MON=-1,TUE,WED=6,THU,FRI,SAT}
so the value for monday = -1;
usually enum ill take the values sequentially, dats if enum month={a=0,b};
her the value for b=1(dats next of 1)
like wise the value for TUE=0;
den wed=6(ITS ALREADY GIVEN),therefore next value s 7 hence THU=7,DEN FRI=8,SAT=9
so the value for monday = -1;
usually enum ill take the values sequentially, dats if enum month={a=0,b};
her the value for b=1(dats next of 1)
like wise the value for TUE=0;
den wed=6(ITS ALREADY GIVEN),therefore next value s 7 hence THU=7,DEN FRI=8,SAT=9
Gayathri said:
1 decade ago
Yes Karthiga, I agree with your concept.
Priya said:
1 decade ago
Thanks karthika.
Mayank said:
1 decade ago
Thanks karthika.
Raja Sekhar said:
1 decade ago
In Enum,
Unless a value is assigned, the elements are given a default integer value which is an increment of the previous one.
So TUE=2 as the increment of the previous one(MON).
As WED is 6 the next will be THU=7, FRI=8, Sat=9
Unless a value is assigned, the elements are given a default integer value which is an increment of the previous one.
So TUE=2 as the increment of the previous one(MON).
As WED is 6 the next will be THU=7, FRI=8, Sat=9
Ashish said:
1 decade ago
Because enum takes the sequentials values by default after assigning a particular number.
When the value wed=6 initialized and others variable not initalized. It runs sequentially.
When the value wed=6 initialized and others variable not initalized. It runs sequentially.
Pragathi said:
1 decade ago
You are right karthika.
Ramdas said:
1 decade ago
Here the given
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
enum has the property of incrementing integer value by 1 to every member in it.
here for first member MON they assigned -1. so for next member its value is 0.according to this for third member it should 1, but the programer assigned 6 to it. hence, for next member it becomes 7(=6+1). The compiler reads previous member value and increment it. so it is 7 and 8, 9
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
enum has the property of incrementing integer value by 1 to every member in it.
here for first member MON they assigned -1. so for next member its value is 0.according to this for third member it should 1, but the programer assigned 6 to it. hence, for next member it becomes 7(=6+1). The compiler reads previous member value and increment it. so it is 7 and 8, 9
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers