In this article, we will discuss the maximum value of unsigned int in C++.
- Unsigned int data type in C++ is used to store 32-bit integers.
- The keyword unsigned is a data type specifier, which only represents non-negative integers i.e. positive numbers and zero.
Some properties of the unsigned int data type are:
- An unsigned data type can only store positive values.
- It takes a size of 32 bits.
- A maximum integer value that can be stored in an unsigned int data type is typically 4, 294, 967, 295, around 232 – 1(but is compiler dependent).
- The maximum value that can be stored in unsigned int is stored as a constant in the <climits> header file. whose value can be used as UINT_MAX.
- A minimum integer value that can be stored in an unsigned int data type is typically 0.
- In case of overflow or underflow of data type, the value is wrapped around.
- For example, if 0 is stored in an int data type and 1 is subtracted from it, the value in that variable will become equal to 4, 294, 967, 295. Similarly, in the case of overflow, the value will round back to 0.
Below is the program to get the highest value that can be stored in unsigned int in C++:
Value from climits constant : 4294967295 Value using the wrap around property : 4294967295