Interpreting bits in union fields as different datatypes in C/C++
Interpreting bits in union fields as different datatypes in C/C++ I am trying to access Union bits as different datatype for example, typedef union { uint64_t x; uint32_t y[2]; }test; test testdata; testdata.x = 0xa; printf("uint64_t: %016lxnuint32_t: %08x %08xn",testdata.x,testdata.y[0],testdata.y[1]); printf("Addresses:nuint64_t: %016lxnuint32_t: %p %pn",&testdata.x,&testdata.y[0],&testdata.y[1]); and the output is uint64_t: 000000000000000a uint32_t: 0000000a 00000000 Addresses: uint64_t: 00007ffe09d594e0 uint32_t: 0x7ffe09d594e0 0x7ffe09d594e4 The starting address pointed to by 'y' is same as starting address of 'x'; Since, both fields uses the same location shouldn't values of 'x' be 00000000 0000000a ? Why this is not happening? How the internal conversion happens in Union with different fields of different datatypes? If we want to retrieve the exact raw bits as uint32_t in the same order ...