Boolean values, which can be either true or false, are represented in C programming by the bool data type. It is a component of the header file and was first included in the C99 standard.
This is a brief explanation:
bool: There are only two possible values for this data type: true (non-zero) and false (zero). It offers a method for utilizing logical conditions and values in C programs.
#include <stdbool.h>
#include <stdio.h>
int main() {
bool a = true;
bool b = false;
if (a) {
printf("This statement is true.\n");
} else {
printf("This statement is false.\n");
}
if (b) {
printf("This statement is true.\n");
} else {
printf("This statement is false.\n");
}
return 0;
}
In this example, we declare boolean variables a and b of type bool
, assign them true and false values respectively, and then use them in conditional statements.