Is an int the same as unsigned or signed?
Is an int the开发者_Go百科 same type as unsigned or signed?
Plain int
is the same as signed
is the same as 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 are signed by default.
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
.
精彩评论