Solution #1: Finding endianness of a machine is to detect whether the machine is little endian or big endian. In a little endian machine the least significant byte is stored first whereas in a big endian machine the most significant byte is stored first. Here is the code,
#include#include int main() { int i = 1; char* ptr = (char*)&i; if(*ptr) printf("Little Endian\n"); else printf("Big Endian\n"); return 0; }