最近在网上看到两道面试题,楼主很困惑,我来解答下.

[题目源地址](http://www.tuicool.com/articles/i2Yzey)


解答

这里写图片描述


//测试平台的大小端
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num = 0x10203040;
    char *p = (char *)&num;

    printf("%d-%d-%d-%d\n", &p[0],&p[1],&p[2],&p[3]);
    printf("%x-%x-%x-%x\n", p[0],p[1],p[2],p[3]);

    if( p[0] == 0x40 )
        printf("小端");
    else
        printf("大端");

    return 0;
}


备份地址: 【平台大小端 , 结构体大小-面试题