c语言有无bool类型
在C语言中,没有内置的bool类型。但是,C99标准引入了stdbool.h头文件,其中定义了_Bool类型,和true和false的宏定义。可以通过包括stdbool.h头文件来使用bool类型。具体示例代码以下:
#include <stdbool.h>
#include <stdio.h>
int main() {
bool b = true;
if (b) {
printf("b is true
");
} else {
printf("b is false
");
}
return 0;
}
上述代码中,我们包括了stdbool.h头文件,并使用了bool类型的变量b,和true和false的宏定义。在条件语句中,我们判断b的值并输出相应的结果。
TOP