Unaligned memory access: is it defined behavior or not? [duplicate]
问题 This question already has an answer here : What does the standard say about unaligned memory access? (1 answer) Closed last year . Consider the following code: #include <iostream> int main() { char* c = new char('a'); char ac[4] = {'a', 'b', 'c', 'd'}; unsigned long long int* u = reinterpret_cast<unsigned long long int*>(c); unsigned long long int* uc = reinterpret_cast<unsigned long long int*>(&ac[3]); *u = 42; *uc = 42; std::cout<<*u<<" "<<*uc<<std::endl; } Is this considered as a valid