10. 计算下列程序输出
/* * exercise19.c * * Created on: 2012-11-5 * Author: xiaobin */ enum myStr { x1, x2, x3=10, x4, x5 }x; int main(int argc, char* argv[]) { x = (enum myStr) 0x801005, 0x8010f4; printf("%x\n", x + 5); return 0; }
然后,要知道枚举变量默认取第一个常量的值,即x1;
最后,要知道编译器对枚举变量不检查取值,即只取所赋的第一个值;
输出结果:
80100a
enum status_type { ok = 200, created = 201, accepted = 202, no_content = 204, multiple_choices = 300, moved_permanently = 301, moved_temporarily = 302, not_modified = 304, bad_request = 400, unauthorized = 401, forbidden = 403, not_found = 404, internal_server_error = 500, not_implemented = 501, bad_gateway = 502, service_unavailable = 503 } status;