当前位置:网站首页>How C language determines whether it is a 32-bit system or a 64 bit system

How C language determines whether it is a 32-bit system or a 64 bit system

2022-07-07 20:11:00 junxuezheng

32 Bit and 64 Bit refers to the number of bits of the operating system , Mapping to C In language , The most intuitive is the number of bytes occupied by the pointer type .

1、32 Bit system :

Address 32 position , So the pointer type also accounts for 32 position , namely 4 byte .

2、64 Bit system :

Address 64 position , So the pointer type also accounts for 64 position , namely 8 byte .

therefore , You only need to judge the value of any pointer sizeof value , You can get the number of digits .

3、demo

#include <iostream>
using namespace std;
int main()
{
    
    int bits = sizeof(char*);
    if (bits == 4) printf("32 position \n");
    else if (bits == 8) printf("64 position \n");
    else printf("others, bits = %d\n", bits); 
}
原网站

版权声明
本文为[junxuezheng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071801455100.html