I am unable to initialize a constant array of a custom type. Following is the code:
union chk {
struct{
int a : 4;
int b : 12;
}stNative;
int nVal;
};
const chk obj[2] = {0x1234, 0x6789};
int main() {
cout << obj[0].nVal<<endl;
}
On Executing the above code, I get some random values. I am not able to understand the reason this is happening and how can it be fixed. O/P of the above code is : 30868