Home > Backend Development > C++ > body text

In C language, the use of bool

王林
Release: 2023-08-28 16:17:03
forward
2112 people have browsed it

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>");
   }
}
Copy after login

Output

my_bool1 is false
my_bool2 is true
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!