SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
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 */

Weitere ähnliche Inhalte

Was ist angesagt?

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9Rumman Ansari
 
Python Conditionals and Functions
Python Conditionals and FunctionsPython Conditionals and Functions
Python Conditionals and FunctionsPooja B S
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11Rumman Ansari
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 

Was ist angesagt? (6)

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
Python Conditionals and Functions
Python Conditionals and FunctionsPython Conditionals and Functions
Python Conditionals and Functions
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Php operators
Php operatorsPhp operators
Php operators
 

Mehr von 웅식 전

15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization웅식 전
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main웅식 전
 
12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation웅식 전
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array웅식 전
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer웅식 전
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function웅식 전
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class웅식 전
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing웅식 전
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing웅식 전
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef웅식 전
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement웅식 전
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib웅식 전
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io웅식 전
 
2 2. operators
2 2. operators2 2. operators
2 2. operators웅식 전
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types웅식 전
 

Mehr von 웅식 전 (20)

15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
 
14. fiile io
14. fiile io14. fiile io
14. fiile io
 
13. structure
13. structure13. structure
13. structure
 
12 2. dynamic allocation
12 2. dynamic allocation12 2. dynamic allocation
12 2. dynamic allocation
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array
 
11. array & pointer
11. array & pointer11. array & pointer
11. array & pointer
 
10. pointer & function
10. pointer & function10. pointer & function
10. pointer & function
 
9. pointer
9. pointer9. pointer
9. pointer
 
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
 
6. function
6. function6. function
6. function
 
5 2. string processing
5 2. string processing5 2. string processing
5 2. string processing
 
5 1. character processing
5 1. character processing5 1. character processing
5 1. character processing
 
15 1. enumeration, typedef
15 1. enumeration, typedef15 1. enumeration, typedef
15 1. enumeration, typedef
 
4. loop
4. loop4. loop
4. loop
 
3 2. if statement
3 2. if statement3 2. if statement
3 2. if statement
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
 
2 2. operators
2 2. operators2 2. operators
2 2. operators
 
2 1. variables & data types
2 1. variables & data types2 1. variables & data types
2 1. variables & data types
 

Kürzlich hochgeladen

8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis UsageNeil Kimberley
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCRashishs7044
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfrichard876048
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyotictsugar
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024Matteo Carbone
 

Kürzlich hochgeladen (20)

Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCREnjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdf
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
Investment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy CheruiyotInvestment in The Coconut Industry by Nancy Cheruiyot
Investment in The Coconut Industry by Nancy Cheruiyot
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 

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 */