printf conversion specifier for _Bool?

前端 未结 5 853
猫巷女王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:24

    There is no specific conversion length modifier for _Bool type.

    _Bool is an unsigned integer type large enough to store the values 0 and 1. You can print a _Bool this way:

    _Bool b = 1;
    printf("%d\n", b);
    

    Because of the integer promotions rules, _Bool is guaranteed to promote to int.

提交回复
热议问题