Upcoming SlideShare
Loading in …5
×

# 15 1. enumeration

338 views
256 views

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

No Downloads
Views
Total views
338
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 15 1. enumeration

1. 1. Enumeration Types
2. 2. 2Enumeration 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. 3Enumeration Types Example#include <stdio.h>#define YELLOW 0#define RED 1#define BLUE 2void 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. 4Enumeration Types Example#include <stdio.h>#define YELLOW 0#define RED 1#define BLUE 2#define Color intvoid 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. 5Enumeration Types enumeration Types– Variables of enum type can be used in indexing expressionsand 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 nameBy 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. 6Enumeration 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. 7typedef 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. 8typedef 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. 9Enumeration 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. 10Enumeration 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 */