x86和x64下指针的大小

根据测试

int main()
{
    int a = 4;
    void *p = (void*)malloc(sizeof(100));
    char *p1 = (char*)malloc(sizeof(100));
    int n1 = sizeof(a);
    int n2 = sizeof(p);
//  int n3 = sizeof(*p); error 
    int n4 =  sizeof(p1);
    int n5 =  sizeof(*p1);
}

x86下

n1 = 4; n2 = 4; n4 = 4; n5 = 1;

x64下

n1 = 4; n2 = 8; n4 = 8; n5 = 1;

小结: 指针在x86下为4个字节长度,在x64下为8个字节长度

            int型在x86/x64下都为4个字节长度

            char型同上,都为1个字节长度

其他我没测。

原文地址:https://www.cnblogs.com/strive-sun/p/12073985.html