大端序小端序问题

    xiaoxiao2021-03-25  90

    #include <stdio.h> int main(void) { int array[] = {1, 2, 3, 4, 5}; int *p = (int *)((int)array + 1); printf("%d\n %x\n", *p, *p); return 0; }

    输出结果: 33554432 2000000

    分析:

    测试方法:

    void bigOrSmall(void) { int data = 0x12345678; char * p = (char *)&data; if(0x78 == *p) printf("small\n"); else printf("big\n"); } //或者 union data { int a; char b; }; void bigOrSmall(void) { union data da ; da.a = 0x12345678; if(0x78 == da.b) printf("small\n"); else printf("big\n"); }
    转载请注明原文地址: https://ju.6miu.com/read-34672.html

    最新回复(0)