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

后端 未结 9 801
执笔经年
执笔经年 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 08:22

    When compiling for x64, the difference between int and long is somewhere between 0 and 4 bytes, depending on what compiler you use.

    GCC uses the LP64 model, which means that ints are 32-bits but longs are 64-bits under 64-bit mode.

    MSVC for example uses the LLP64 model, which means both ints and longs are 32-bits even in 64-bit mode.

提交回复
热议问题