> For the complete documentation index, see [llms.txt](https://mr-poston-1.gitbook.io/c++/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mr-poston-1.gitbook.io/c++/1.-c++-basics/1.2-basic-data-types/1.2.4-booleans.md).

# 1.2.4 Booleans

Like other computer languages, Booleans are true/false variables. They work very much like any other computer languages but do have one aspect a little different than a language such as Java.

In C++, Booleans are declared as type `bool`. They can be declared and initialized or just declared, just like other variables that you saw in C++.

```
bool b1 = true;

bool b2;
b2 = false;
```

The one thing that is a little different compared to Java is that Booleans are stored and printed as either a 1 or 0. (1 for true).

```
cout << b1 << endl; // true = 1
```

You can actually assign them values of 1 and 0 as well, but `true` and `false` will work for the definition.

### Logical Operators

Like Java and other languages, C++ makes use of logical operators for Booleans. See the table below.

| Operator | Description                                                                    |
| -------- | ------------------------------------------------------------------------------ |
| `&&`     | And operator. If both values are true, returns true, otherwise returns false.  |
| `\|\|`   | Or operator. If either value is true, returns true, otherwise returns false.   |
| `!`      | Not operator. Returns the opposite value. For example, if true, returns false. |

### Try This Example

{% embed url="<https://onlinegdb.com/75Yt3eK5n>" %}
Booleans
{% endembed %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mr-poston-1.gitbook.io/c++/1.-c++-basics/1.2-basic-data-types/1.2.4-booleans.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
