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