1、
#include <stdio.h> enum a {x, y, z}; int main(void) { printf("x = %d\n", x); printf("y = %d\n", y); printf("z = %d\n", z); return 0; }
2、
#include <stdio.h> enum a {x = 888, y = 1000, z = 123}; int main(void) { printf("x = %d\n", x); printf("y = %d\n", y); printf("z = %d\n", z); return 0; }
3、
#include <stdio.h> enum animal {Dog, Cat, Monkey, Invalid}; void dog(void) { puts("wang wang."); } void cat(void) { puts("miao miao"); } void monkey(void) { puts("ji ji"); } enum animal select(void) { enum animal tmp; do { puts("0: dog 1: cat 2: monkey 3: quit."); printf("tmp = "); scanf("%d", &tmp); } while(tmp < Dog || tmp > Invalid); return tmp; } int main(void) { enum animal a; do { switch(a = select()) { case Dog: dog(); break; case Cat: cat(); break; case Monkey: monkey(); break; } } while(a != Invalid); return 0; }