天天看點

判斷系統是大端位元組序還是小端位元組序的C代碼

#include <iostream>
int main()
{
    short int i = 0x0102;
    char *pc = (char *)&i;

    if (pc[0] == 1)
    {
        std::cout << "big endian" << std::endl;
    }
    else
    {
        std::cout << "small endian" << std::endl;
    }

    return 0;
}
           

(SAW:Game Over!)