How to define and use the bool type in the C language?
In C language, the bool type is usually defined by including the stdbool.h header file. The bool type can represent a true or false value.
Example of defining a boolean type:
#include <stdbool.h>
bool flag = true;
Example using bool type:
#include <stdio.h>
#include <stdbool.h>
int main() {
bool flag = true;
if (flag) {
printf("The flag is true.\n");
} else {
printf("The flag is false.\n");
}
return 0;
}
In C language, true is defined as 1, and false is defined as 0. Therefore, you can directly assign true and false to variables of type bool, or use bool variables in conditional statements for evaluation.