+ 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.

26th Dec 2017, 1:54 PM
Eryl Deverton
Eryl Deverton - avatar
3 Answers
+ 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.
26th Dec 2017, 2:01 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 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
26th Dec 2017, 2:00 PM
David Akhihiero
David Akhihiero - avatar
+ 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.
26th Dec 2017, 2:06 PM
Mustafa K.
Mustafa K. - avatar