void main()
{
int n = 1;
// little endian if true
if(*(char *)&n == 1)
printf("This is little endian\n");
else
printf("This is big endian\n");
}
Suppose we are on a 32-bit machine.
And char type is 8 bits