SlideShare a Scribd company logo
1 of 10
1
• An enumeration is a user-defined data type that consists of integral
constants. To define an enumeration, keyword enum is used.
• enum flag { const1, const2, ..., constN };
• Here, name of the enumeration is flag.
• And, const1, const2,...., constN are values of type flag.
• By default, const1 is 0, const2 is 1 and so on. You can change default
values of enum elements during declaration (if necessary).
• // Changing default values of enum
• enum suit {
club = 0,
diamonds = 10,
hearts = 20,
spades = 3
};
2
Enumerated Type Declaration
• When you create an enumerated type, only blueprint for
the variable is created. Here's how you can create variables
of enum type.
enum boolean { false, true };
enum boolean check;
• Here, a variable check of type enum boolean is created.
• Here is another way to declare same check variable using
different syntax.
enum boolean
{ false,
true } check;
3
Example: Enumeration Type
4
Why enums are used in C
programming?
• Enum variable takes only one value out of many possible
values. Example to demonstrate it, This makes enum a good
choice to work with flags.
5
• It's because the size of an integer is 4 bytes.
• This makes enum a good choice to work with
flags.
• You can accomplish the same task
using structures. However, working with
enums gives you efficiency along with
flexibility.
6
How to use enums for flags?
• Suppose you are designing a button for Windows application.
You can set flags ITALICS, BOLD and UNDERLINE to work with
text.
• here is a reason why all the integral constants are power of 2
in above pseudocode.
7
• Since, the integral constants are power of 2, you can combine two or more
flags at once without overlapping using bitwise OR | operator. This allows
you to choose two or more flags at once. For example,
8
• When the output is 5, you always know that
bold and underline is used.
• Also, you can add flag to your requirements.
9
10

More Related Content

What's hot (20)

Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Data types in C
Data types in CData types in C
Data types in C
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
File in C language
File in C languageFile in C language
File in C language
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Structure in C
Structure in CStructure in C
Structure in C
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Structure in c
Structure in cStructure in c
Structure in c
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 

Similar to C programming enumeration

Enumerated data types
Enumerated data typesEnumerated data types
Enumerated data typesAnkit Sinha
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
Lamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckLamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckseidounsemel
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptxZubairAli256321
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxMurali M
 
CIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and VariablesCIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and VariablesHamad Odhabi
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxssusere336f4
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Blue Elephant Consulting
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Blue Elephant Consulting
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)Dilawar Khan
 
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdfLec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdfRahulKumar342376
 

Similar to C programming enumeration (20)

12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Enumerated data types
Enumerated data typesEnumerated data types
Enumerated data types
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
lec 2.pptx
lec 2.pptxlec 2.pptx
lec 2.pptx
 
Typescript-7 (1).pptx
Typescript-7 (1).pptxTypescript-7 (1).pptx
Typescript-7 (1).pptx
 
Lamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ckLamborghini Veneno Allegheri #2004@f**ck
Lamborghini Veneno Allegheri #2004@f**ck
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
 
CIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and VariablesCIS 1403 Lab 2- Data Types and Variables
CIS 1403 Lab 2- Data Types and Variables
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
kotlin-nutshell.pptx
kotlin-nutshell.pptxkotlin-nutshell.pptx
kotlin-nutshell.pptx
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
 
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdfLec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
 
Cobol basics 19-6-2010
Cobol basics 19-6-2010Cobol basics 19-6-2010
Cobol basics 19-6-2010
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

C programming enumeration

  • 1. 1
  • 2. • An enumeration is a user-defined data type that consists of integral constants. To define an enumeration, keyword enum is used. • enum flag { const1, const2, ..., constN }; • Here, name of the enumeration is flag. • And, const1, const2,...., constN are values of type flag. • By default, const1 is 0, const2 is 1 and so on. You can change default values of enum elements during declaration (if necessary). • // Changing default values of enum • enum suit { club = 0, diamonds = 10, hearts = 20, spades = 3 }; 2
  • 3. Enumerated Type Declaration • When you create an enumerated type, only blueprint for the variable is created. Here's how you can create variables of enum type. enum boolean { false, true }; enum boolean check; • Here, a variable check of type enum boolean is created. • Here is another way to declare same check variable using different syntax. enum boolean { false, true } check; 3
  • 5. Why enums are used in C programming? • Enum variable takes only one value out of many possible values. Example to demonstrate it, This makes enum a good choice to work with flags. 5
  • 6. • It's because the size of an integer is 4 bytes. • This makes enum a good choice to work with flags. • You can accomplish the same task using structures. However, working with enums gives you efficiency along with flexibility. 6
  • 7. How to use enums for flags? • Suppose you are designing a button for Windows application. You can set flags ITALICS, BOLD and UNDERLINE to work with text. • here is a reason why all the integral constants are power of 2 in above pseudocode. 7
  • 8. • Since, the integral constants are power of 2, you can combine two or more flags at once without overlapping using bitwise OR | operator. This allows you to choose two or more flags at once. For example, 8
  • 9. • When the output is 5, you always know that bold and underline is used. • Also, you can add flag to your requirements. 9
  • 10. 10