# Booleans

**URL:** <https://forum.arduino.cc/t/booleans/88218>\
**Category:** Programming\
**Created:** [February 3, 2012, 2:05pm UTC](https://forum.arduino.cc/t/booleans/88218 "2012-02-03T14:05:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 3, 2012, 2:05pm UTC](https://forum.arduino.cc/t/booleans/88218/1 "2012-02-03T14:05:33Z")

</div>

Hi,

I'm currently writing a library and I need to use booleans.

When programming in C++ I usually use "bool" and not "boolean".  
Is there any difference ? Which one should I use ?

Thanks.

Pollop.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 3, 2012, 2:10pm UTC](https://forum.arduino.cc/t/booleans/88218/2 "2012-02-03T14:10:59Z")

</div>

You can use either. I don't think there is a difference, other than boolean is the keywords file that the IDE uses to hilight words.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 3, 2012, 3:12pm UTC](https://forum.arduino.cc/t/booleans/88218/3 "2012-02-03T15:12:53Z")

</div>

Hi,  
in C++ "bool" is a built-in data type that can have values "true" or "false". In any case in C and C++ language the test conditions are considered FALSE when the result is zero and TRUE if not ( if(2) { printf("true\n"); } is a correct statement.)  
In Arduino.h you can find the following type definition:

typedef uint8\_t boolean;

so the boolean type is defined in the arduino environment as a byte. Note that the C++ standard does not specify what is the size of a bool type, it is implementation dependent. Usually in microcontroller programming, because of the limited resources and 'low level' applications that normally are required, it's important to know how the variables are represented in memory. From the boolean typedef you see immediately that it will be stored in 8 bits as an unsigned byte.  
Also the byte type is defined in arduino.h as a uint8\_t.  
I suggest to use the types defined in the arduino environment.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 3, 2012, 3:16pm UTC](https://forum.arduino.cc/t/booleans/88218/4 "2012-02-03T15:16:01Z")

</div>

That's true, but I don't know if the IDE pre-processor does anything to convert it to a bool.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 7:42pm UTC](https://forum.arduino.cc/t/booleans/88218/5 "2021-05-05T19:42:32Z")

</div>

Closed on May 5, 2021, 7:42pm UTC


