SlideShare a Scribd company logo
Enumeration Types
2
Enumeration Types
 Example
#include <stdio.h>
void main(void)
{
int color ;
for( color = 0 ; color <= 2 ; color++ ) {
switch( color ) {
case 0 : printf( “Yellown” ) ; break ;
case 1 : printf( “Redn” ) ; break ;
case 2 : printf( “Bluen” ) ; break ;
}
}
}
3
Enumeration Types
 Example
#include <stdio.h>
#define YELLOW 0
#define RED 1
#define BLUE 2
void main(void)
{
int color ;
for( color = YELLOW ; color <= BLUE ; color++ ) {
switch( color ) {
case YELLOW : printf( “Yellown” ) ; break ;
case RED : printf( “Redn” ) ; break ;
case BLUE : printf( “Bluen” ) ; break ;
}
}
}
4
Enumeration Types
 Example
#include <stdio.h>
#define YELLOW 0
#define RED 1
#define BLUE 2
#define Color int
void main(void)
{
Color color ;
for( color = YELLOW ; color <= BLUE ; color++ ) {
switch( color ) {
case YELLOW : printf( “Yellown” ) ; break ;
case RED : printf( “Redn” ) ; break ;
case BLUE : printf( “Bluen” ) ; break ;
}
}
}
5
Enumeration Types
 enumeration Types
– Variables of enum type can be used in indexing expressions
and as operands of all arithmetic and relational operators
[Ex]
enum day { sun, mon, tue, wed, thu, fri, sat };
enum day d1, d2;
d1 = fri;
tag name
By default, the first element ‘sun’ is associated with 0.
The next element, mon, is associated with 1.
…
Define variables d1, d2 as type of enum ‘day’,
Assign a value of fri to d1
6
Enumeration Types
 Example
#include <stdio.h>
enum color_type {Yellow, Red, Blue} ;
void main(void) {
enum color_type color ;
for( color = Yellow ; color <= Blue ; color++ ) {
switch( color ) {
case Yellow : printf( “Yellown” ) ; break ;
case Red : printf( “Redn” ) ; break ;
case Blue : printf( “Bluen” ) ; break ;
}
}
}
7
typedef
 Example
#include <stdio.h>
enum color_type {Yellow, Red, Blue} ;
typedef enum color_type Color ;
void main(void) {
Color color ;
for( color = Yellow ; color <= Blue ; color++ ) {
switch( color ) {
case Yellow : printf( “Yellown” ) ; break ;
case Red : printf( “Redn” ) ; break ;
case Blue : printf( “Bluen” ) ; break ;
}
} }
8
typedef
 Example
#include <stdio.h>
typedef enum {Yellow, Red, Blue} Color ;
void main(void) {
Color color ;
for( color = Yellow ; color <= Blue ; color++ ) {
switch( color ) {
case Yellow : printf( “Yellown” ) ; break ;
case Red : printf( “Redn” ) ; break ;
case Blue : printf( “Bluen” ) ; break ;
}
}
}
9
Enumeration Types
 enumeration Types
[Ex]
enum day { sun=10, mon, tue, wed=24, thu, fri, sat=36 };
[Ex]
#define sun 10
#define mon 11
#define tue 12
#define wed 13
#define thu 24
#define fri 25
#define sat 36
10
Enumeration Types
 Feature of enum type
– enum types are equivalent to integer type
[Ex]
int i;
enum { CLUBS, DIAMONDS, HEARTS, SPADES } s;
i = DIAMONDS; /* i = 1 */
s = 0; /* s = CLUBS */
s++; /* s = 1 */
i = s + 2; /* i =3 */

More Related Content

PPTX
CHAPTER 4
PDF
9. pointer, pointer & function
PPTX
C if else
PPSX
Break and continue statement in C
DOCX
computer graphics at openGL (2)
PPT
Intro to c programming
PPSX
C lecture 3 control statements slideshare
CHAPTER 4
9. pointer, pointer & function
C if else
Break and continue statement in C
computer graphics at openGL (2)
Intro to c programming
C lecture 3 control statements slideshare

What's hot (6)

PPTX
Conditional Statement in C Language
PPTX
C Programming Language Part 9
PPTX
Python Conditionals and Functions
PPTX
C Programming Language Part 11
PPTX
C Programming Language Part 8
PPTX
Php operators
Conditional Statement in C Language
C Programming Language Part 9
Python Conditionals and Functions
C Programming Language Part 11
C Programming Language Part 8
Php operators
Ad

Similar to 15 1. enumeration (20)

PPTX
PPTX
Enumration datatype
PPTX
Enumerated data types
PPT
User defined data type
PDF
ENUM - make u r names as data types
PPT
Enumerated data types in C
PPTX
C programming enumeration
PPTX
Data types in C
PPSX
6 enumerated, typedef
PDF
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
PPTX
21CS642 Module 1 Enumerations PPT.pptx VI SEM CSE 2021 Batch Students
PPTX
Enumeration type
PPTX
8enum in c#
PPT
Basic of c &c++
PPTX
discuss about the union & structure in python
DOCX
What kind of a variable or ADT can be modelled with an enum -SolutionA.docx
PPT
C Programming Intro.ppt
PPTX
Enum
PPTX
data types in c programming language in detail
PPTX
datatypes and specifiers_and variables.pptx
Enumration datatype
Enumerated data types
User defined data type
ENUM - make u r names as data types
Enumerated data types in C
C programming enumeration
Data types in C
6 enumerated, typedef
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
21CS642 Module 1 Enumerations PPT.pptx VI SEM CSE 2021 Batch Students
Enumeration type
8enum in c#
Basic of c &c++
discuss about the union & structure in python
What kind of a variable or ADT can be modelled with an enum -SolutionA.docx
C Programming Intro.ppt
Enum
data types in c programming language in detail
datatypes and specifiers_and variables.pptx
Ad

More from 웅식 전 (20)

PDF
15 3. modulization
PDF
15 2. arguement passing to main
PDF
14. fiile io
PDF
13. structure
PDF
12 2. dynamic allocation
PDF
12 1. multi-dimensional array
PDF
11. array & pointer
PDF
10. pointer & function
PDF
9. pointer
PDF
7. variable scope rule,-storage_class
PDF
6. function
PDF
5 2. string processing
PDF
5 1. character processing
PDF
15 1. enumeration, typedef
PDF
4. loop
PDF
3 2. if statement
PDF
3 1. preprocessor, math, stdlib
PDF
2 3. standard io
PDF
2 2. operators
PDF
2 1. variables & data types
15 3. modulization
15 2. arguement passing to main
14. fiile io
13. structure
12 2. dynamic allocation
12 1. multi-dimensional array
11. array & pointer
10. pointer & function
9. pointer
7. variable scope rule,-storage_class
6. function
5 2. string processing
5 1. character processing
15 1. enumeration, typedef
4. loop
3 2. if statement
3 1. preprocessor, math, stdlib
2 3. standard io
2 2. operators
2 1. variables & data types

Recently uploaded (20)

PDF
NISM Series V-A MFD Workbook v December 2024.khhhjtgvwevoypdnew one must use ...
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PDF
Unit 1 Cost Accounting - Cost sheet
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PPTX
2025 Product Deck V1.0.pptxCATALOGTCLCIA
PDF
How to Get Business Funding for Small Business Fast
PPTX
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PDF
Daniels 2024 Inclusive, Sustainable Development
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
Roadmap Map-digital Banking feature MB,IB,AB
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
PPTX
3. HISTORICAL PERSPECTIVE UNIIT 3^..pptx
PPT
Chapter four Project-Preparation material
PDF
How to Get Funding for Your Trucking Business
PDF
Nidhal Samdaie CV - International Business Consultant
PDF
Deliverable file - Regulatory guideline analysis.pdf
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
NISM Series V-A MFD Workbook v December 2024.khhhjtgvwevoypdnew one must use ...
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
Unit 1 Cost Accounting - Cost sheet
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
2025 Product Deck V1.0.pptxCATALOGTCLCIA
How to Get Business Funding for Small Business Fast
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
Daniels 2024 Inclusive, Sustainable Development
HR Introduction Slide (1).pptx on hr intro
Roadmap Map-digital Banking feature MB,IB,AB
COST SHEET- Tender and Quotation unit 2.pdf
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
3. HISTORICAL PERSPECTIVE UNIIT 3^..pptx
Chapter four Project-Preparation material
How to Get Funding for Your Trucking Business
Nidhal Samdaie CV - International Business Consultant
Deliverable file - Regulatory guideline analysis.pdf
Dragon_Fruit_Cultivation_in Nepal ppt.pptx

15 1. enumeration

  • 2. 2 Enumeration Types  Example #include <stdio.h> void main(void) { int color ; for( color = 0 ; color <= 2 ; color++ ) { switch( color ) { case 0 : printf( “Yellown” ) ; break ; case 1 : printf( “Redn” ) ; break ; case 2 : printf( “Bluen” ) ; break ; } } }
  • 3. 3 Enumeration Types  Example #include <stdio.h> #define YELLOW 0 #define RED 1 #define BLUE 2 void main(void) { int color ; for( color = YELLOW ; color <= BLUE ; color++ ) { switch( color ) { case YELLOW : printf( “Yellown” ) ; break ; case RED : printf( “Redn” ) ; break ; case BLUE : printf( “Bluen” ) ; break ; } } }
  • 4. 4 Enumeration Types  Example #include <stdio.h> #define YELLOW 0 #define RED 1 #define BLUE 2 #define Color int void main(void) { Color color ; for( color = YELLOW ; color <= BLUE ; color++ ) { switch( color ) { case YELLOW : printf( “Yellown” ) ; break ; case RED : printf( “Redn” ) ; break ; case BLUE : printf( “Bluen” ) ; break ; } } }
  • 5. 5 Enumeration Types  enumeration Types – Variables of enum type can be used in indexing expressions and as operands of all arithmetic and relational operators [Ex] enum day { sun, mon, tue, wed, thu, fri, sat }; enum day d1, d2; d1 = fri; tag name By default, the first element ‘sun’ is associated with 0. The next element, mon, is associated with 1. … Define variables d1, d2 as type of enum ‘day’, Assign a value of fri to d1
  • 6. 6 Enumeration Types  Example #include <stdio.h> enum color_type {Yellow, Red, Blue} ; void main(void) { enum color_type color ; for( color = Yellow ; color <= Blue ; color++ ) { switch( color ) { case Yellow : printf( “Yellown” ) ; break ; case Red : printf( “Redn” ) ; break ; case Blue : printf( “Bluen” ) ; break ; } } }
  • 7. 7 typedef  Example #include <stdio.h> enum color_type {Yellow, Red, Blue} ; typedef enum color_type Color ; void main(void) { Color color ; for( color = Yellow ; color <= Blue ; color++ ) { switch( color ) { case Yellow : printf( “Yellown” ) ; break ; case Red : printf( “Redn” ) ; break ; case Blue : printf( “Bluen” ) ; break ; } } }
  • 8. 8 typedef  Example #include <stdio.h> typedef enum {Yellow, Red, Blue} Color ; void main(void) { Color color ; for( color = Yellow ; color <= Blue ; color++ ) { switch( color ) { case Yellow : printf( “Yellown” ) ; break ; case Red : printf( “Redn” ) ; break ; case Blue : printf( “Bluen” ) ; break ; } } }
  • 9. 9 Enumeration Types  enumeration Types [Ex] enum day { sun=10, mon, tue, wed=24, thu, fri, sat=36 }; [Ex] #define sun 10 #define mon 11 #define tue 12 #define wed 13 #define thu 24 #define fri 25 #define sat 36
  • 10. 10 Enumeration Types  Feature of enum type – enum types are equivalent to integer type [Ex] int i; enum { CLUBS, DIAMONDS, HEARTS, SPADES } s; i = DIAMONDS; /* i = 1 */ s = 0; /* s = CLUBS */ s++; /* s = 1 */ i = s + 2; /* i =3 */