int是与unsigned或signed相同的类型吗?
Plain int
与signed
相同, signed int
相同
C++ Standard 3.9.1/2:
There are four signed integer types : “signed char”, “short int”, “int”, and “long int.” <...>
C++ Standard 3.9.1/3:
For each of the signed integer types, there exists a corresponding ( but different ) unsigned integer type : “unsigned char”, “unsigned short int”, “unsigned int”, and “unsigned long int,” <...>
So, sizeof(int)
is equal to sizeof(unsigned)
. But boost::is_same< int, unsigned >::value
is false.
ints
are signed by default, as are longs
.
So, int
, signed
and signed int
are the same thing.
Similarly long
and signed long
are the same.
chars
on the other hand, don't have a default. Implementations can consider them signed or unsigned (many have a command line switch to choose). char
, signed char
and unsigned char
are considered three distinct types for overload resolution, template instaniation and other places.
int
s默认签名。
signed int
is the same as int
and specifies an integer value that can have both positive and negative values.
unsigned int
on the other hand can only have positive values, so the greatest positive value is much larger than that of a signed int
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.