Some properties of the unsigned short int data type are:
- Being an unsigned data type, it can store only positive values.
- Takes a size of 16 bits.
- A maximum integer value that can be stored in an unsigned short int data type is typically 65535, around 216 – 1(but is compiler dependent).
- The maximum value that can be stored in unsigned short int is stored as a constant in <climits> header file whose value can be used as USHRT_MAX.
- The minimum value that can be stored in unsigned short int is zero.
- In case of overflow or underflow of data type, the value is wrapped around. For example, if 0 is stored in an unsigned short int data type and 1 is subtracted from it, the value in that variable will become equal to 65535. Similarly, in the case of overflow, the value will round back to zero.
Below is the program to get the highest value that can be stored in unsigned short int in C++:
Value from climits constant: 65535 Value using the wrap around property: 65535