When are unsigned integers preferred over signed integers?

Q4. When are unsigned integers preferred over signed integers? What is the advantage of unsigned integers over signed integers?

Ans. The prefix unsigned makes the integer types not to hold negative values. For instance, if short (2-byte long) represents the range -32768 to +32767, then the unsigned version can represent the range 0 to 65535. This has the advantage of increasing the largest value the variables can hold. Unsigned types are used for quantities that are never negative such as populations, sports scores, inventory counts etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

310 Views
%d bloggers like this: