在下面的示例中,我尝试扫描布尔类型变量的值。当我在 GCC 中编译时,我收到以下警告:
warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘_Bool *’ [-Wformat=]
scanf("%d", &b);
Code:
#include <stdio.h>
#include <stdbool.h>
int main()
{
bool b;
scanf("%d", &b);
printf("%d\n", b);
}
C 中有 bool 格式说明符吗?
没有格式说明符bool
输入C。
For printf
,你可以依靠隐式提升int
,并使用%d
作为指定的格式化程序。
For scanf
,你应该将其读入int
,并进行适当转换。再次,使用%d
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)