user336635
user336635

Reputation: 2281

Is an int the same as unsigned or signed?

Is an int the same type as unsigned or signed?

Upvotes: 13

Views: 1429

Answers (5)

James Curran
James Curran

Reputation: 103495

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.

Upvotes: 3

the_void
the_void

Reputation: 5538

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.

Upvotes: 1

Kirill V. Lyadvinsky
Kirill V. Lyadvinsky

Reputation: 99565

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.

Upvotes: 11

cHao
cHao

Reputation: 86506

ints are signed by default.

Upvotes: 2

Anthony Williams
Anthony Williams

Reputation: 68571

Plain int is the same as signed is the same as signed int

Upvotes: 14

Related Questions