2011年(100)
分类: C/C++
2011-04-21 17:05:14
enum enumeration_name { value1, value2, value3, . . } object_names; |
enum colors_t {black, blue, green, cyan, red, purple, yellow, white}; |
1 2 3 4 | colors_t mycolor; mycolor = blue; if (mycolor == green) mycolor = red; |
1 2 3 | enum months_t { january=1, february, march, april, may, june, july, august, september, october, november, december} y2k; |
union union_name { member_type1 member_name1; member_type2 member_name2; member_type3 member_name3; . . } object_names; |
1 2 3 4 5 | union mytypes_t { char c; int i; float f; } mytypes; |
1 2 3 | mytypes.c mytypes.i mytypes.f |
onezeroone2011-04-24 16:23:53
enum---created a whole new data type from scratch without basing it on any other existing type。
union---All the elements of the union declaration occupy the same physical space in memory。