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

后端 未结 9 756
执笔经年
执笔经年 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:20

    The C++ Standard says it like this :

    3.9.1, §2 :

    There are five signed integer types : "signed char", "short int", "int", "long int", and "long long int". In this list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural size suggested by the architecture of the execution environment (44); the other signed integer types are provided to meet special needs.

    (44) that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header .

    The conclusion : it depends on which architecture you're working on. Any other assumption is false.

提交回复
热议问题