Enumeration in C language Reviewed by Momizat on . The enumeration data type is a user define datatype with value ranging over a finite set of identifies called enumeration constants. [php] // syntax enum <ty The enumeration data type is a user define datatype with value ranging over a finite set of identifies called enumeration constants. [php] // syntax enum <ty Rating: 0

Enumeration in C language

The enumeration data type is a user define datatype with value ranging over a finite set of identifies called enumeration constants.

// syntax enum <type>{contrant....};
enum color{red,green,blue};

This example defines color to be a new datatype which can be assume the value red,green,blue each of this is a enumeration constant here color can be use has a new datatype enumeration is a convenient way to associate constant integer with meaningful name.the advantage is to getting the value automatically use of enumeration constrant is general makes the program easier to read and change.

Syntax:-enum {constrant……..};

Ex:- Que-Input day number and print day.

#include <stdio.h>;
#include <conio.h>;
enum day
{
	sun=1,
	mon=2,
	tue=3,
	wed=4,
	thur=5,
	fri=6,
	sat=7
};
main(){
	clrscr();
	int d;
	printf("Enter a day number:");
	scanf("%d",&d);
	switch(d){
		case sun:
			printf("Sunday");
			break;
		case mon:
			printf("Monday");
			break;
		case tue:
			printf("Tuesday");
			break;
		case wed:
			printf("Wednesday");
			break;
		case thur:
			printf("Thursday");
			break;
		case fri:
			printf("Friday");
			break;
		case sat:
			printf("saturday");
			break;
		Default:
			printf("Invalid Number of day");
			break;
	
	}
	getch();

}

Leave a Comment

© 2014 Powered By