How can I find Endian-ness of my PC programmatically using C?

Dinesh picture Dinesh · Dec 20, 2011 · Viewed 24k times · Source

Possible Duplicate:
Detecting endianness programmatically in a C++ program

Is there any library function available to find the endian-ness of my PC?

Answer

COD3BOY picture COD3BOY · Dec 20, 2011

Why you need a library if you can find it like this? :)

int num = 1;

if (*(char *)&num == 1)
{
    printf("Little-Endian\n");
}
else
{
    printf("Big-Endian\n");
}