How to print an unsigned char in C?

前端 未结 6 2242
梦如初夏
梦如初夏 2020-11-29 02:34

I am trying to print char as positive value:

char ch = 212;
printf(\"%u\", ch);

but I get:

4294967252

How

6条回答
  •  清酒与你
    2020-11-29 02:43

    Because char is by default signed declared that means the range of the variable is

    -127 to +127>

    your value is overflowed. To get the desired value you have to declared the unsigned modifier. the modifier's (unsigned) range is:

     0 to 255
    

    to get the the range of any data type follow the process 2^bit example charis 8 bit length to get its range just 2 ^(power) 8.

提交回复
热议问题