printf的转换说明符_Bool? [英] printf conversion specifier for _Bool?

查看:148
本文介绍了printf的转换说明符_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆