Maximum value of signed char in C++
Some properties of the signed char data type are:
- It is generally used to store 8-bit characters.
- Being a signed data type, it can store positive values as well as negative values.
- Size of 8 bits is occupied where 1 bit is used to store the sign of the value.
- A maximum value that can be stored in a signed char data type is typically 127, around 27 – 1(but is compiler dependent).
- The maximum and minimum value that can be stored in a signed char is stored as a constant in climits header file and can be named as SCHAR_MAX and SCHAR_MIN respectively.
- A minimum value that can be stored in a signed char data type is typically -128, i.e. around –27 (but is compiler dependent).
- In case of overflow or underflow of data type, the value is wrapped around. For example, if -128 is stored in a signed char data type and 1 is subtracted from it, the value in that variable will become equal to 127. Similarly, in the case of overflow, the value will round back to -128.
Below is the program to get the highest value that can be stored in signed char in C++:
Maximum value from climits constant: 127 Minimum value from climits constant: -128 Maximum value using the wrap around property: 127 Maximum value using the wrap around property: -128
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