Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
When I run this code, it enters an indefinite loop. Where did I go wrong?
#include <stdio.h> int main() { char x; x=0; while(x<=225) { printf("%c=%d\n",x,x); x=x+1; } return 0; }
char
signed
x
-128
127
unsigned char
If the type char behaves as the type signed char then the valid range of values is [-128, 127]. It is undefined behavior when after increment the result value exceeds 127.
signed char
[-128, 127]
Instead of the type char you can use the type unsigned char.
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
charis probablysignedin your implementation soxhas the range-128to127.unsigned char