Home > Article > Backend Development > In C language, the use of bool
In C language, there is no predefined bool data type. We can create boolean values using enumerations. An enumeration will be created as bool and then have false and true as elements of the enumeration. false will be in the first position so it will retain 0 and true will be in the second position so it will get the value 1. Now we can use it as data type.
#include<stdio.h> typedef enum { F, T } boolean; main() { boolean my_bool1, my_bool2; my_bool1 = F; if(my_bool1 == F) { printf("my_bool1 is false</p><p>"); } else { printf("my_bool1 is true</p><p>"); } my_bool2 = 2; if(my_bool2 == F) { printf("my_bool2 is false</p><p>"); } else { printf("my_bool2 is true</p><p>"); } }
my_bool1 is false my_bool2 is true
The above is the detailed content of In C language, the use of bool. For more information, please follow other related articles on the PHP Chinese website!