Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++strict aliasing rulesSingle-choice MCQ

Under the strict aliasing rule, which access is undefined behavior because it reads an object through a glvalue of an incompatible type (assuming no special permitted exception applies)?

float f = 1.0f; unsigned bits = *reinterpret_cast<unsigned*>(&f); // (A) int i = 42; char* cp = reinterpret_cast<char*>(&i); char c = cp[0]; // (B)