Maximum value of unsigned short int in C++
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
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up