How to print 1 byte with printf?

后端 未结 4 615
难免孤独
难免孤独 2020-12-31 08:17

I know that when using %x with printf() we are printing 4 bytes (an int in hexadecimal) from the stack. But I would like to print only

4条回答
  •  孤城傲影
    2020-12-31 08:33

    You can use the following solution to print one byte with printf:

    unsigned char c = 255;
    printf("Unsigned char: %hhu\n", c);
    

提交回复
热议问题