Maximum value of unsigned char in C++
In this article, we will discuss the maximum value of unsigned char data type in C++.
Some properties of the unsigned char data type are:
- Being an unsigned data type, it can store only positive values.
- Unsigned char data type in C++ is used to store 8-bit characters.
- A maximum value that can be stored in an unsigned char data type is typically 255, around 28 – 1(but is compiler dependent).
- The maximum value that can be stored in an unsigned char is stored as a constant in the <climits> header file, whose value can be used as UCHAR_MAX.
- A minimum value that can be stored in an unsigned char data type is 0.
- In case of overflow or underflow of data type, the value is wrapped around.
- For example, if 0 is stored in an unsigned char data type and 1 is subtracted from it, the value in that variable will become equal to 255. 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 char in C++:
valueFromLimits = UCHAR_MAX;
"Value from climits "
"constant : "
value = 0;
value = value - 1;
"Value using the wrap "
"around property : "
Value from climits constant : 255
Value using the wrap around property : 255
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!