With printf()
, I can use %hhu
for unsigned char
, %hi
for a short int
, %zu
for a size_t
, %tx
for a ptrdiff_t
, etc.
What conversion format specifier do I use for a _Bool
? Does one exist in the standard?
Or do I have to cast it like this:
_Bool foo = 1;
printf("foo: %i\n", (int)foo);
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
.