Enumeration in C Language

Posted on

C Enumeration

 

Enumeration in C Language

An enum is a key phrase, it’s an consumer outlined knowledge kind. All properties of integer are utilized on Enumeration knowledge kind so measurement of the enumerator knowledge kind is 2 byte. It work just like the Integer.

It’s used for creating an consumer outlined knowledge kind of integer. Utilizing enum we will create sequence of integer fixed worth.

Syntax

  • In above syntax enum is a key phrase. It’s a consumer defiend knowledge kind.
  • In above syntax tagname is our personal variable. tagname is any variable identify.
  • value1, value2, value3,…. are create set of enum values.

enumeration - Enumeration in C Language

It’s begin with 0 (zero) by default and worth is incremented by 1 for the sequential identifiers within the checklist. If fixed one worth will not be initialized then by default sequence might be begin from zero and subsequent to generated worth must be earlier fixed worth one.

 

Learn rigorously

Instance of Enumeration in C

  • In above code first line is create consumer outlined knowledge kind referred to as week.
  • week variable have 7 worth which is inside { } braces.
  • at this time variable is declare as week kind which will be initialize any knowledge or worth amongst 7 (solar, mon,….).

Instance of Enumeration in C

Output

Instance of Enumeration in C

Output

Right here “enum week” is consumer outlined knowledge kind and at this time is integer kind variable which initialize Tuesday. In above code we add “at this time+1” as a result of enum is begin from 0, so to get correct reply we add “1”. Different smart it give “2nd day”.

Instance of Enumeration in C

Output

In above code change solar, mon, tue,…. with Equal numeric worth 0, 1, 2,…