C 的 带值枚举
等级 4197 次按键
为HTTP状态码定义具有显式整数值的枚举。
C 代码
// 每个常量都显式指定值,而不是默认的0、1、21enum HttpStatus {2 OK = 200,3 NOT_FOUND = 404,4 SERVER_ERROR = 5005};6 // 声明枚举变量7enum HttpStatus status = NOT_FOUND;// %d打印其数值:4048printf("Status code: %d\n", status);// 使用枚举常量名进行比较9if (status == NOT_FOUND) {10 printf("Page not found\n");11}运行结果
Status code: 404 Page not found
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 C 代码中需要输入的符号及其出现次数。
=× 6_× 4;× 4"× 4,× 3(× 3)× 3{× 2}× 2\× 2