C program to check little vs. big endian

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
C program to check little vs. big endian_第1张图片
C program to check little vs. big endian_第2张图片

你可能感兴趣的:(c语言,开发语言)