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.
ANIL B RATHOD said:
1 year 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.
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:
6 years ago
It's clear to understand, Thanks @Karthika.
Keerthana said:
6 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.
Hence the output:-1, 0, 6, 7, 8, 9.
(8)
Kamal said:
6 years ago
Yes, I agree @Karthika and @Akansha.
Karth said:
7 years ago
Yes, I agree with your concept @Karthika.
Manoja V. said:
7 years ago
Thank you @Karthika.
Ramkesh said:
7 years ago
Nice Explanation, Thank You @Ramdas.
Akanksha said:
10 years ago
Enum is short form use for Enumerated data type definition. Correct me if I m wrong.
Puneet said:
10 years ago
Enum stand for?
Sudha said:
10 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.
Union stores in memory in same data type in same place. But continue memory allocation.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers