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);
%d is print as an int %s is print as a string %f is print as floating point.
The println(boolean) method of PrintStream Class in Java is used to print the specified boolean value on the stream and then break the line. This boolean value is taken as a parameter. Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the stream.
In C we have seen different format specifiers. Here we will see another format specifier called %p. This is used to print the pointer type data.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With