C programming language does not have a built-in boolean data type like some other programming languages. However, C provides support for boolean values using standard C library macros defined in the stdbool.h header file.
The stdbool.h header file defines two macros that can be used to represent boolean values:
-
bool: This macro represents a boolean value and can have two possible values:trueorfalse. In C programming language,trueis defined as 1, andfalseis defined as 0. -
trueandfalse: These macros represent the boolean valuestrueandfalse, respectively.
Example:
#include <stdbool.h>
#include <stdio.h>
int main() {
bool a = true;
bool b = false;
if (a) {
printf("a is true\n");
}
if (!b) {
printf("b is false\n");
}
return 0;
}
In the above example, we have included the stdbool.h header file and declared two boolean variables a and b. We have also used the if statement to check the boolean values of a and b.
Note that in C programming language, any non-zero value is considered true, and 0 is considered false. However, it is good practice to use the true and false macros to make the code more readable and maintainable.

Comments