As per C
standard, there are three distinct types.
a char
a signed char
an unsigned char
gcc
by default takes plain char as signed char. in a 2's complement machine following things would happen when ever char value exceeds $127$.
- Likewise in the above program, it will print $-121$
The following program will stop for an unsigned char. But loop forever for a signed char
#include <stdio.h>
int main() {
unsigned char c = 0; // loops forever for char c = 0;
while(c < 130) {
printf("hello\n");
c++;
}
return 0;
}