将stdbool.h添加到源文件时,可以使用bool作为类型名称。stdbool.h将符号true和false定义为分别对应于1和0。当转换为bool类型时,非零数值将导致1(true),0将转换为0(false)。
如果在源文件中包含标头,则可以按如下方式编写声明:
#include <stdio.h>
#include <stdbool.h>
int main(void) {
bool valid = true; // Boolean variable initialized to true
printf("%d",valid);
return 0;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/266671.html