I have a question about typecasting the reference of a variable of type double. What is exactly happening when &d
becomes typecasted into an unsigned char*
? How is typecasting the address of a variable valid and what is it actually doing?
#include <stdio.h>
int main(void) {
// examining object representation is a legitimate use of cast
double d = 3.14;
printf("The double %.2f(%a) is: ", d, d);
for(size_t n = 0; n < sizeof d; ++n)
printf("0x%02x ", ((unsigned char*)&d)[n]); // <--
}
And how do the array brackets work in this case?