Just a little question : Today I got back to the value the variable types can hold and I wondered if an int defined without short or long is always short or long, like signed or unsigned!
int i ; //short or long ?
Just a little question : Today I got back to the value the variable types can hold and I wondered if an int defined without short or long is always short or long, like signed or unsigned!
int i ; //short or long ?
No. int
is a distinct type from short
and long
. short
, int
, and long
can have 3 different sizes. (Also, note that usually, instead of modifying int
as short int
or long int
, it's generally preferred to just write short
or long
.)
It's neither. On a lot of systems, including the usual Linuxes, int will be 32 bits, short will be 16, and long 64. This isn't guaranteed by the C language however--the types need to be ordered by size but they don't have to be those specific sizes (e.g. int could be 64 bits on some systems, or 16).
The answer is "neither". int
without a modifier is int
, short int
is no larger than int
and may be the same size. long int
is no smaller than int
, but may be the same size. This is all according to the C++ standard, which also says that short
must be at least 16 bits, and long
should be at least 32 bits. But it's entirely possible to have a machine where all are 32 or 64 bits.
Unless specified, int is always signed.
Just to know, short is 16 bits, long is 32 bits, and int is either 16 or 32 bits depending on compiler. Unless specified, all these are signed by default.