+ 1
What is bool???
Boolean
5 Answers
+ 15
To add to @Sean's answer, any value assigned to a Boolean variable which is not 0 or false, is automatically evaluated to true.
+ 8
Is the Datatype That have two value true and False (0)(1) Respectively
+ 2
A boolean is a data type that can be either true (1) or false (0).
+ 2
For example, let's say you have a list of items to buy in a store. When you get your empty cart, the state of all items is initially false (or not picked yet). Once you put the item in the cart, you mark the item as true (already picked). That way, you can easily check the list and see which items were picked and which are yet to pick.
Is also used to represent the state of conditions. For example, to check if an item is repeated in a list (count > 1), if time is over in a soccer match, if the value of x solves a given equation...
0
@Hatsy Rey, you can't assign non-boolean values to bool variable in C# (see the tag). And there is no "automatic evaluation". So, you would get compilation error if you would do something like:
bool b = 1;
It would be possible to do something like this in C++ if I am not wrong âșïž