Output:Code:#include <iostream> int main() { int x = 0x12345678; char* p = reinterpret_cast<char*>(&x); std::cout << std::hex << "0x" << (int)p[0] << "\n0x" << (int)p[1] << "\n0x" << (int)p[2] << "\n0x" << (int)p[3] << std::endl; if (p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12) std::cout << "Congratulations! Your machine is little endian!\n"; else if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78) std::cout << "Congratulations! Your machine is big endian!\n"; else std::cout << "Weird. Your machine is neither little endian nor big endian.\n"; }
0x78
0x56
0x34
0x12
Congratulations! Your machine is little endian!
Press any key to continue . . .



LinkBack URL
About LinkBacks




