By default, char signed char in C. If you want to print 255 , use unsigned char however I explain the output in the context of signed char so that the concept becomes clear. If you write j=127 , then it will print 127 , since the bit representation is 01111111. But if you write j=128 then it will print -128 because the bit representation 01111111 has increased by 1 to become 10000000. now, if you write j=255 then the bit representation is 11111111. therefore it will print -1 If you write j=256 then it will print 0 because when the bit representation 11111111 increases by 1, it becomes 100000000. But only 1 byte is allocated for the characher variable, so the left the bit itself is not saved, and the bit representation becomes 00000000. Also, if if you write j=257 then this is also an overflow case, and the bit representation will become 00000001 and 1 will be printed.
source share