Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++undefined behavior catalogSingle-choice MCQ

What does the standard say about this code, and why is it a frequently-missed undefined behavior?

#include <cstring> struct T { int a; }; void* mem = ::operator new(sizeof(T)); T* p = static_cast<T*>(mem); p->a = 42; // (1) int x = p->a; // (2)