#include <stdio.h>
int main()
{
char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
Explanation:
In C, char is typically a signed data type unless explicitly declared as unsigned char. The range of a signed char is -128 to 127 (for 8-bit systems).
What happens when chr = 128; ?
- 128 is out of the valid range of a signed char (-128 to 127).
- Since char is signed by default, 128 undergoes integer overflow (wrap-around behavior).
- The value stored in chr becomes -128 if char is signed.
However, the output depends on the compiler settings:
- If char is signed (default in most compilers) β Output: -128
- If char is unsigned β Output: 128
Thus, the output depends on the compiler and its default char behavior.