A1: Yes, this will be undefined behavior when accessing cp [8].
A2: Yes, it also does not print cp [0].
As shown, it prints bytes 7, 8, 5, 6, 3, 4, 2, 1 of valid values ββ0..7. So, if you correctly copied the code from the book, there is an error in the code of the book. Check the error page for the book, if there is one.
It is also strange that he unwinds the cycle; simpler wording:
for (int i = sizeof(double); i-- > 0; ) printBinary(cp[i]);
There is also, apparently, a good reason for printing bytes in reverse order; itβs not obvious what it will be.
source share