printf conversion specifier for _Bool?

前端 未结 5 880
猫巷女王i
猫巷女王i 2021-02-19 09:04

With printf(), I can use %hhu for unsigned char, %hi for a short int, %zu for a size_t

5条回答
  •  春和景丽
    2021-02-19 09:41

    Until C99, bool was not apart of standard C, and thus did not exist as a printf modifier. C99, defined _Bool (which you are using) to be an integer, thus you should be fine casting it as an integer to display (at least from a machine perspective). Alternatively, you could do something like:

    printf("%d",foo?1:0);
    

提交回复
热议问题