+ 1

Please, Explain the following...

signed char chr; chr = 128; printf("%d",chr); //Output is : -128 //How ???

14th May 2019, 1:22 PM
Sp Maurya
Sp Maurya - avatar
2 Respuestas
+ 3
signed char range is -128 to 127 according to the 2-complement representation. So, we have overflow and it will be round-off to fit it in the range. That’s why, 128 round-off to -128. /* signed char chr = 128 prints ==> -128 signed char chr = 129 prints ==> -127 signed char chr = 130 prints ==> -126 ... signed char chr = 255 prints ==> -1 signed char chr = 256 prints ==> 0 signed char chr = 257 prints ==> 1 ... */
14th May 2019, 1:30 PM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
+ 2
ok... i got it thanks for your help...
14th May 2019, 1:55 PM
Sp Maurya
Sp Maurya - avatar