Does the C language have a bool type?
In C language, there is no built-in bool type. However, the C99 standard introduced the stdbool.h header file, which defines the _Bool type, as well as the macro definitions for true and false. You can use the bool type by including the stdbool.h header file. An example code is as follows:
#include <stdbool.h>
#include <stdio.h>
int main() {
bool b = true;
if (b) {
printf("b is true\n");
} else {
printf("b is false\n");
}
return 0;
}
In the code above, we included the stdbool.h header file, and used a bool type variable b, as well as the macro definitions for true and false. In the conditional statement, we check the value of b and output the corresponding result.