本文共 1351 字,大约阅读时间需要 4 分钟。
c 语言 整数布尔值
C originally did not have native support for boolean values.
C最初不支持布尔值。
C99, the version of released in 1999⁄2000, introduced a boolean type.
C99是1999年 / 2000年发布的版本,引入了布尔类型。
To use it, however, you need to import a header file, so I’m not sure we can technically call it “native”. Anyway, we do have a bool
type.
但是,要使用它,您需要导入头文件,因此我不确定我们在技术上可以称其为“本机”。 无论如何,我们确实有bool
类型。
You can use it like this:
您可以像这样使用它:
#include#include int main(void) { bool isDone = true; if (isDone) { printf("done\n"); } isDone = false; if (!isDone) { printf("not done\n"); }}
If you’re programming the Arduino, you can use bool
without including stdbool
because bool
is a valid and built-in C++ data type, and the is C++.
如果您正在对Arduino进行编程,则可以在不包含stdbool
情况下使用bool
,因为bool
是有效的内置C ++数据类型,而是C ++。
In plain C, remember to #include <stdbool.h>
otherwise you’ll get a bunch of errors at declaration and any time you use the bool
variable:
在普通C语言中,请记住#include <stdbool.h>
否则在声明时以及每次使用bool
变量时都会出现很多错误:
➜ ~ gcc hello.c -o hello; ./hellohello.c:4:3: error: use of undeclared identifier 'bool' bool isDone = true; ^hello.c:5:7: error: use of undeclared identifier 'isDone' if (isDone) { ^hello.c:8:8: error: use of undeclared identifier 'isDone' if (!isDone) { ^3 errors generated.
翻译自:
c 语言 整数布尔值
转载地址:http://mwqgb.baihongyu.com/