C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 11)
11.
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
Error
0, 1, 6, 3, 4, 5
0, 0, 6, 7, 8, 9
Answer: Option
Explanation:
Because ++ or -- cannot be done on enum value.
Discussion:
8 comments Page 1 of 1.

K kushal said:   2 years ago
@All.

Enum is constants otherwise macros can be used.

Pranali said:   8 years ago
In enum datatype, Ony one member is active at a time. Rest of all are not in used at that time.

Priya said:   1 decade ago
The error because of ++Mon & Tue?

Because both have 0 their default value. I think.

Shanks said:   1 decade ago
Enum is enumerated data type. It's like a customized user defined data type. With its help you can define a data type on you own which takes on values specified by you in its declaration.

Madhav said:   1 decade ago
Please can anyone explain enum in detail??

Pakhi said:   1 decade ago
Increament and decrement operations cannot be performed in user defined data types. For example in enum, structure, union.
(1)

Balaji Roy said:   1 decade ago
Enum is a user-defined data type, no operations can be done on user-defined data types, to be operated they must be type casted to primitive data types.

Vinay said:   1 decade ago
Can anyone explain. ?

Post your comments here:

Your comments will be displayed after verification.