Usually in C we use int to represent boolean values, like:
int a = 0;
But sometimes use bool to define the boolean type, and use true & false to represent the value will make our code more clear. I just found out that you can do this by including stdbool.h file:
#include <stdio.h>
#include <stdbool.h>
int main() {
bool rainyDay = false;
printf("Rainy day: %d\n", rainyDay);
return 0;
}
Compile and run it:
Rainy day: 0
Actually the stdbool.h just defined the bool using #define, which map the bool type to _Bool, true to 1 and false to 0. Check the full source code here.
Top comments (0)