Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Basics of C Programming
  5. Constants
  6. Enumeration Constants

Enumeration Constants

Table of Contents show

Enumerated data type is a user defined data type

Syntax

[storage class specifier][type_qualifier]enum [tag-name]{enumeration-list}
  • The terms enclosed in the square brackets are optional.
  • Each enumerator is an enumeration list names a value. The enumeration constants are like symbolic constants except that their values are set automatically.
  • By default the first enumerator has the value 0. Each subsequent enumerator if not explicitly assigned a value, has a value 1 greater than the value of the enumerator that immediately produces it

Example

enum cars{alto,omni,esteem=3,wagonR,swft=1,dzire}
  • The first enumerator, i.e. alto is automatically initialized to 0
  • The second enumerator omni  has the value 1
  • The third enumerator esteem has explicitly given a value 3
  • The enumerator constant wagonR will have the value as 4 (3+1)
  • The enumerator constants swift and dzire will have the values 1 and 2 respectively

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments