How to use bool in c?

There is no bool data type in C. In C99 standerd version, the boolean variable has been added as _Bool. Additionally, a new header stdbool.h has been added for compatibility reasons. This header allows programmers to use boolean types in the same way, as in C++ language.

To use bool in C, we can use enum as below.

1
2
3
4
5
6
7
8
9
10
11
12
enum bool {
    false, true
};
 
bool value;
value = bool(0); // False
value = bool(1); // True
 
if(value == false)
	printf("Value is false");
else
	printf("Value is true");

Here we can use variable ‘value’ as boolean variable.

One Response to “How to use bool in c?”

  1. manish

    hello Ranjith, i want to depth knowlage in c or c . mene c k andar kuch games or projects banaye hai

    Reply

Leave a Reply