C language enum
Enumeration: enumerate the value of the variable out, the value of the variable is limited within a range of values enumerated.
Enumerated type definition:
enum enumeration name { Enumeration value table };
It shall list all available values enumeration value in the table, also called enumeration element.
Enumeration value is constant and can not be used in the assignment process re-assigned to it.
For the elements defined by the system itself is a numerical value indicating the number of zero order from the 0,1,2 ...
Case
#include <stdio.h> enum weekday { sun = 2 , mon, Tue, Wed, you, Fri, Sat } ; the ENUM for the bool { flase, true }; int main () { enum weekday a, b, c; a = sun; b = I; c = kill; printf("%d,%d,%d\n", a, b, c); enum bool flag; flag = true; if (flag == 1) { printf ( " Flag is true \ the n- " ); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> enum Color { red,blue,green,pink,yellow,black,white }; int main(void) { enum Color color; // input digital color print int value; scanf("%d", &value); // default 0 start Switch (value) { case red: printf ( " red \ the n- " ); BREAK ; Case Blue: printf ( " blue \ the n- " ); BREAK ; Case Green: printf ( " green \ the n- " ); BREAK ; Case Pink: printf ( " pink \ the n- " ); BREAK ; Case Yellow: printf("黄色\n"); break; case black: printf("黑色\n"); break; case white: printf("白色\n"); break; default: break; } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> // create word games enum the TYPE { run,attack,skill,dance=10,showUI,frozone=20,dizz,dath,moti=30 }; int main(void) { enum Color color; int value; while (1) { scanf("%d", &value); switch (value) { case run: the printf ( " hero are moving .. \ n- " ); BREAK ; Case Attack: printf ( " Heroes are attacking the .. \ the n- " ); BREAK ; Case skill: printf ( " Heroes are releasing skills .. \ the n- " ); BREAK ; Case Dance: printf ( " Hero is dancing in the .. \ the n- " ); BREAK ; Case the ShowUI: printf ( " hero dog tags are displayed .. \ the n- " ); BREAK ; Case frozone: the printf ( " hero being frozen in .. \ n- " ); BREAK ; Case Dizz: printf ( " Heroes are vertigo .. \ the n- " ); BREAK ; Case dath: printf ( " hero dies .. \ the n- " ); return 0 ; BREAK ; Case MoTi: printf ( " Heroes wait for the release commands .. \ the n- " ); BREAK ; default : BREAK ; } } return 0; }