printf的转换说明符_Bool? [英] printf conversion specifier for _Bool?
问题描述
使用的printf()
,我可以使用%HHU
为 unsigned char型
,%喜
为短整型
,%祖
为为size_t
,%TX
为 ptrdiff_t的
等。
怎样使用转换格式说明了 _Bool
?难道一个在标准存在?
还是我必须投这样的:
_Bool富= 1;
的printf(富:%I \\ N(INT)富);
有是没有具体的转换长度修改 _Bool
键入
_Bool
是符号的整数类型足够大的存储值 0
和 1
。您可以打印 _Bool
是这样的:
_Bool B = 1;
的printf(%d个\\ N,B);
由于的整数促销规则, _Bool
是保证促进 INT
。
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
.
这篇关于printf的转换说明符_Bool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!