What is the difference between an int and a long in C++?

后端 未结 9 794
执笔经年
执笔经年 2020-11-22 07:15

Correct me if I am wrong,

int is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31)
long is 4 bytes, with a range of values from -2,147,

9条回答
  •  佛祖请我去吃肉
    2020-11-22 07:58

    It is implementation dependent.

    For example, under Windows they are the same, but for example on Alpha systems a long was 64 bits whereas an int was 32 bits. This article covers the rules for the Intel C++ compiler on variable platforms. To summarize:

      OS           arch           size
    Windows       IA-32        4 bytes
    Windows       Intel 64     4 bytes
    Windows       IA-64        4 bytes
    Linux         IA-32        4 bytes
    Linux         Intel 64     8 bytes
    Linux         IA-64        8 bytes
    Mac OS X      IA-32        4 bytes
    Mac OS X      Intel 64     8 bytes  
    

提交回复
热议问题