I have read that the sizeof union gives the largest size of member in the union.But when i do this:i'm getting unexpected results:
#include <iostream>
using namespace std;
union RecordType
{
int arr[9];
double x;
};
int main()
{
RecordType t;
cout << sizeof(t); //output is 40,instead of 36 (9*4bytes each)
}
why is the size 40 instead of 36 and even if i change the array to "int arr[10]",then sizeof gives the output as 40 (same as in the case of "int arr[9]),whats internally happening here?