SlideShare a Scribd company logo
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

PPTX
Union in C programming
PPTX
Pointers in C Programming
PPTX
C programming language
PDF
Module 05 Preprocessor and Macros in C
PPT
Basic concepts of object oriented programming
PPTX
File handling in c
PPTX
PPTX
Array Of Pointers
Union in C programming
Pointers in C Programming
C programming language
Module 05 Preprocessor and Macros in C
Basic concepts of object oriented programming
File handling in c
Array Of Pointers

What's hot (20)

DOC
Arrays and Strings
PPT
c-programming
PPTX
Characteristics of OOPS
PPTX
Structure of C program
PPT
Enumerated data types in C
PPTX
C Programming: Structure and Union
PDF
PPTX
Structure in c language
PDF
Arrays In C
PPTX
Basic Data Types in C++
PPTX
Data types in C language
PPTX
Concept of c data types
PPT
Structure of a C program
PDF
DATABASE MANAGEMENT SYSTEM LAB.pdf
PPTX
Data types in c++
PPTX
System calls
PPTX
Type casting in c programming
PPTX
Introduction to C programming
PPTX
File in C language
PPTX
Data types in C
Arrays and Strings
c-programming
Characteristics of OOPS
Structure of C program
Enumerated data types in C
C Programming: Structure and Union
Structure in c language
Arrays In C
Basic Data Types in C++
Data types in C language
Concept of c data types
Structure of a C program
DATABASE MANAGEMENT SYSTEM LAB.pdf
Data types in c++
System calls
Type casting in c programming
Introduction to C programming
File in C language
Data types in C
Ad

Similar to C programming enumeration (20)

PPTX
12.6-12.9.pptx
PPTX
Arrays.pptx
PPTX
Go Language Programming Basic Introduction
PPTX
Enumerated data types
PPTX
Presentation 2nd
PPTX
lec 2.pptx
PPTX
Typescript-7 (1).pptx
PDF
Lamborghini Veneno Allegheri #2004@f**ck
PPTX
Programming fundamental 02.pptx
PPTX
Vba Class Level 1
PPTX
Computer Studies 2013 Curriculum framework 11 Notes ppt.pptx
PPTX
Js tutorial(Basic concepts, running a program ,console,variable,types etc..)
PPTX
C Programming Lecture 3 - Elements of C.pptx
PDF
CIS 1403 Lab 2- Data Types and Variables
PPTX
classVII_Coding_Teacher_Presentation.pptx
PPTX
Lecture 2
PPTX
kotlin-nutshell.pptx
PPTX
Intro To C++ - Class 11 - Converting between types, formatting floating point...
PPTX
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
PPTX
classVIII_Coding_Teacher_Presentation.pptx
12.6-12.9.pptx
Arrays.pptx
Go Language Programming Basic Introduction
Enumerated data types
Presentation 2nd
lec 2.pptx
Typescript-7 (1).pptx
Lamborghini Veneno Allegheri #2004@f**ck
Programming fundamental 02.pptx
Vba Class Level 1
Computer Studies 2013 Curriculum framework 11 Notes ppt.pptx
Js tutorial(Basic concepts, running a program ,console,variable,types etc..)
C Programming Lecture 3 - Elements of C.pptx
CIS 1403 Lab 2- Data Types and Variables
classVII_Coding_Teacher_Presentation.pptx
Lecture 2
kotlin-nutshell.pptx
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
classVIII_Coding_Teacher_Presentation.pptx
Ad

Recently uploaded (20)

PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
From loneliness to social connection charting
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
Business Ethics Teaching Materials for college
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
O5-L3 Freight Transport Ops (International) V1.pdf
NOI Hackathon - Summer Edition - GreenThumber.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
From loneliness to social connection charting
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Business Ethics Teaching Materials for college
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
O7-L3 Supply Chain Operations - ICLT Program
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
Cell Structure & Organelles in detailed.
Onica Farming 24rsclub profitable farm business
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Anesthesia in Laparoscopic Surgery in India
Week 4 Term 3 Study Techniques revisited.pptx

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