# Booleans in C

> Learn how to use booleans in C, where the bool type added in C99 needs #include <stdbool.h> before you can use true and false in your programs.

Author: Flavio Copes | Published: 2020-02-11 | Canonical: https://flaviocopes.com/c-boolean/

C originally did not have native support for boolean values.

C99, the version of [C](https://flaviocopes.com/c-introduction/) released in 1999/2000, introduced a boolean type.

To use it, however, you need to import a header file, so I'm not sure we can technically call it "native". Anyway, we do have a `bool` type.

You can use it like this:

```c
#include <stdio.h>
#include <stdbool.h>

int main(void) {
  bool isDone = true;
  if (isDone) {
    printf("done\n");
  }

  isDone = false;
  if (!isDone) {
    printf("not done\n");
  }
}
```

If you're programming the Arduino, you can use `bool` without including `stdbool` because `bool` is a valid and built-in C++ data type, and the [Arduino Language](https://flaviocopes.com/arduino-programming-language/) is C++.

In plain C, remember to `#include <stdbool.h>` otherwise you'll get a bunch of errors at declaration and any time you use the `bool` variable:

```
➜  ~ gcc hello.c -o hello; ./hello
hello.c:4:3: error: use of undeclared identifier
      'bool'
  bool isDone = true;
  ^
hello.c:5:7: error: use of undeclared identifier
      'isDone'
  if (isDone) {
      ^
hello.c:8:8: error: use of undeclared identifier
      'isDone'
  if (!isDone) {
       ^
3 errors generated.
```
