Enumeration in C Language

Posted on

C Enumeration

 

Enumeration in C Language

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

It’s used for creating an person outlined knowledge sort of integer. Utilizing enum we are able to create sequence of integer fixed worth.

Syntax

  • In above syntax enum is a key phrase. It’s a person defiend knowledge sort.
  • In above syntax tagname is our personal variable. tagname is any variable title.
  • 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 listing. If fixed one worth will not be initialized then by default sequence can be begin from zero and subsequent to generated worth needs to be earlier fixed worth one.

 

Learn fastidiously

Instance of Enumeration in C

  • In above code first line is create person outlined knowledge sort referred to as week.
  • week variable have 7 worth which is inside { } braces.
  • right this moment variable is declare as week sort which may 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 person outlined knowledge sort and right this moment is integer sort variable which initialize Tuesday. In above code we add “right this moment+1” as a result of enum is begin from 0, so to get correct reply we add “1”. Different sensible it give “2nd day”.

Instance of Enumeration in C

Output

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