Skip to main content

Posts

Showing posts with the label Enumerated Data Type

Enumerated Data Type

Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.The symbolically declared members are integer constants. The keyword enum is used to declare an enumeration type. The general construct used to declare an enumeration type is enum tag_name {member1, member2, member3,..,member} variable1, variable2,..,variable n In this declaration, either tag_name or variable may be omitted or both may be present. But at least one of them must exist in this declaration construct. The members are integer constants. By default the first member member1 assigned value 0 member2 assigned value 1 and so on. Eg: enum week{Mon, Tue, Wed,Thu,Fri,Sat}; enum week day; // Or enum week{Mon, Tue, Wed,Thu,Fri,Sat}day; #include <stdio.h> enum day {sunday, monday, tuesday, wednesday, thursday, friday, saturday}; int main() { enum day d = thursday; printf("The day number