# Difference between bool and boolean

**URL:** <https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096>\
**Category:** Programming\
**Created:** [June 23, 2023, 11:40pm UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096 "2023-06-23T23:40:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![elijah57](https://avatars.discourse-cdn.com/v4/letter/e/2bfe46/32.png) [@elijah57](https://forum.arduino.cc/u/elijah57)\
**Post date:** [June 23, 2023, 11:40pm UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/1 "2023-06-23T23:40:14Z")

</div>

Is bool a datatype or boolean a datatype??  
Which is which, i can't tell the difference?

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [June 23, 2023, 11:48pm UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/2 "2023-06-23T23:48:13Z")

</div>

> [@elijah57](#):
>
> Is bool a datatype or boolean a datatype??

If you look in Arduino.h, you'll find:

```arduino
typedef bool boolean;

```

---

<div class="post-metadata">

**Author:** ![lastchancename](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lastchancename/32/215426_2.png) [@lastchancename](https://forum.arduino.cc/u/lastchancename)\
**Post date:** [June 23, 2023, 11:56pm UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/3 "2023-06-23T23:56:01Z")

</div>

Worth noting  
Boolean in Arduino land still occupies a full byte.

If you’re keen, try implementing bit fields as manually setting, clearing bits in a byte defined by yourself.

8/16/32 bit is a lot more space efficient.

---

<div class="post-metadata">

**Author:** ![ruilviana](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ruilviana/32/722429_2.png) [@ruilviana](https://forum.arduino.cc/u/ruilviana)\
**Post date:** [June 23, 2023, 11:56pm UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/4 "2023-06-23T23:56:12Z")

</div>

Are the same thing  
boolean or bool . bool short for boolean.  
Like integer and int. int short for integer.

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [June 24, 2023, 6:53am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/5 "2023-06-24T06:53:40Z")

</div>

> [@elijah57](#):
>
> i can't tell the difference?

boolean is a bool in Arduino context. Not worth to use.  
Just use bool.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [June 24, 2023, 7:49am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/6 "2023-06-24T07:49:40Z")

</div>

> [@noiasca](#):
>
> Just use bool.

+1

Same as the `byte` data type. They are just synonyms of the real thing meant to make code supposedly more readable to some.

Learn the real thing

---

<div class="post-metadata">

**Author:** ![ruilviana](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ruilviana/32/722429_2.png) [@ruilviana](https://forum.arduino.cc/u/ruilviana)\
**Post date:** [June 24, 2023, 11:42am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/7 "2023-06-24T11:42:10Z")

</div>

The bool type occupies the space of one byte,  
but it can only assume values 0 or 1. (true or false)  
The byte type also occupies only one byte,  
 but can assume values from 0 to 15 (0x00 to 0x0F)..  
sorry  
but can assume values from 0 to 255 (0x00 to 0xFF).

See this example code:

> **[Bool\_Byte - Wokwi ESP32, STM32, Arduino Simulator](https://wokwi.com/projects/368415038180945921)**
>
> Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [June 24, 2023, 11:48am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/8 "2023-06-24T11:48:36Z")

</div>

> [@ruilviana](#):
>
> The byte type also occupies only one byte,  
> but can assume values from 0 to 15 (0x00 to 0x0F).

Oops

---

<div class="post-metadata">

**Author:** ![ruilviana](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ruilviana/32/722429_2.png) [@ruilviana](https://forum.arduino.cc/u/ruilviana)\
**Post date:** [June 24, 2023, 11:53am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/9 "2023-06-24T11:53:25Z")

</div>

tks

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [June 24, 2023, 11:54am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/10 "2023-06-24T11:54:20Z")

</div>

> [@ruilviana](#):
>
> The bool type occupies the space of one byte,  
> but it can only assume values 0 or 1. (true or false)

in C++ bool is a native type, so it's not 0 or 1, it's really to be seen as holding a truth value (true or false). The fact that you can get an implicit promotion to an integral type with 0 being false and 1 being true is something else that is there for historical / C compatibility reason but should not be encouraged.

Note also that the value of `sizeof(bool)` is implementation defined and might differ from 1 - so from a pure standard perspective a bool could occupy more than 1 byte.

for more on types, read [Fundamental types - cppreference.com](https://en.cppreference.com/w/cpp/language/types)

---

<div class="post-metadata">

**Author:** ![stitech](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stitech/32/1016377_2.png) [@stitech](https://forum.arduino.cc/u/stitech)\
**Post date:** [October 15, 2023, 5:23am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/11 "2023-10-15T05:23:58Z")

</div>

Recently I was looking at a some disassembled programming, and it came to me why the discussion about bool, Boolean and datatypes is so confusing. The question asked is something like: is it char? Is it byte? 1 or 2 bnytes?

Bool or Boolean is usually not used as data but as the choice to take a certain jump or not. Therefore the question whether it is 1 byte or 2, type char, byte or int, is missing the point.  
In C++ a datatype bool is defined, because the compiler needs to deal with condition jumps, but it is _not_ byte, char or int!

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [October 15, 2023, 10:19am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/12 "2023-10-15T10:19:17Z")

</div>

bool is the official C++ data type for a truth value  
boolean is something arduino defined to be fancy 🙂 but it's the same thing

> <https://github.com/arduino/ArduinoCore-avr/blob/63092126a406402022f943ac048fa195ed7e944b/cores/arduino/Arduino.h#L126-L126>

the [standard says](https://en.cppreference.com/w/cpp/language/types)

> **Boolean type**  
> bool — type, capable of holding one of the two values: true or false. The value of sizeof(bool) is implementation defined and might differ from 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:** [April 12, 2024, 10:20am UTC](https://forum.arduino.cc/t/difference-between-bool-and-boolean/1141096/13 "2024-04-12T10:20:08Z")

</div>

Closed on April 12, 2024, 10:20am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
