#include using namespace std; struct X { union { int i; char c[sizeof(int)]; } foo; }; int main(void) { X* p = new X; p->foo.i = 0x04030201; if (p->foo.c[0] == 1) cout << "Little endian\n"; else cout << "Big endian\n"; return 0; }