Home >Backend Development >C++ >In C language, the use of bool

In C language, the use of bool

王林
王林forward
2023-08-28 16:17:032142browse

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.

Example

#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>");
   }
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete