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 ? 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.
int is guaranteed to have at least 16 bits, which covers that range, but in most modern systems, an int is 32 bits. It could be 36, 48 or 64 bits too. If you have specific requirements that your variables have a certain range, then using typedefs that define types of X bits (or "no less than X") is a good idea. There is cstdint and stdint.h (for C++ and C respectively) that define a number of types like uint32_t and uint_least32_t for this purpose. If you don't care, use int.INT_MAX and INT_MIN to find out (from cstdint), or numeric_limits<int>::max() and numeric_limits<int>::min() from the limits header.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).
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.
short is at least 16 bits, int is at least 16 bits, long is at least 32 bits. Further, sizeof(short) <= sizeof(int) and sizeof(int) <= sizeof(long).