+ 2
Unsigned long and short?
In the C++ tutorials, they don't explain this that well, what is the difference between long and short in an unsigned integer? Please provide an example, it really helps me understand. Thanks.
3 Antworten
+ 15
Unsigned means that numbers will not have a signum (+/-) thus makes them 1 bit smaller in size. Long and Short are numeric datatypes with different size. short is smaller than long... For more info i would recommend to search google.
+ 10
An unsigned integer is an integer that can only hold positive values, integer values are normally allocated 4 bytes(that is 32bits), signed integers can hold a value only up to 2**31 - 1, the first bit is reserved for the sign(positive or negative) but unsigned integers can hold up to 2**32 - 1 since the first bit is unreserved.(Note "**" represents exponent)
A short is an integer that is allocated just 2 bytes(16bits) while a long is allocated 8 bytes(64bits) meaning long can store a larger number than ordinary int
+ 1
unsigned short int -> 2 byte -> 0 and 65,535
short int -> 2 byte -> -32,768 and 32,767
long int -> 4 byte -> -2,147,483,648 and 2,147,483,648
unsigned CAN'T hold NEGATIVE numbers.