This is a C ++ test question, not a homework.
#include <iostream> using namespace std; enum months_t { january, february, march, april, may, june, july, august, september, october, november, december} y2k; int main () { cout << "sizeof months_t is " << sizeof(months_t) << endl; cout << "sizeof y2k is " << sizeof(y2k) << endl; enum months_t1 { january, february, march, april, may, june, july, august, september, october, november, december} y2k1; cout << "sizeof months_t1 is " << sizeof(months_t1) << endl; cout << "sizeof y2k1 is " << sizeof(y2k1) << endl; }
Output:
sizeof months_t is 4
sizeof y2k - 4
sizeof months_t1 - 4
sizeof y2k1 is 4
Why is the size of all these 4 bytes? Not 12 x 4 = 48 bytes?
I know that union elements occupy the same memory location, but this is an enumeration.
c ++ enums sizeof
user1002288 Nov 13 '11 at 23:13 2011-11-13 23:13
source share