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:true
orfalse
. In C programming language,true
is defined as 1, andfalse
is defined as 0. -
true
andfalse
: These macros represent the boolean valuestrue
andfalse
, 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