How do I printf() a uint16_t?

后端 未结 3 1656
天涯浪人
天涯浪人 2021-02-05 06:27

I need to use printf() to print a uint16_t. This SO answer (How to print uint32_t and uint16_t variables value?) says I need to use inttypes.h.

However, I\'m working on

3条回答
  •  一向
    一向 (楼主)
    2021-02-05 06:45

    An obvious way is:

    printf("%u\n", (unsigned int)x);
    

    The unsigned int is guaranteed to be at least 16 bits, so this is not a lossy conversion.

提交回复
热议问题