Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Booleans | Conditional Statements
Introduction to C++
course content

Зміст курсу

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

bookBooleans

Let’s discuss boolean (or logical) data type in more detail. The variable type of bool can take only two values - True (1) or False (0). The boolean can be used when we want to check some logical conditions in our code. For example, you want to know if the variable x is bigger than y to use this information by looking for the difference between them.

For this reason, there are some logical operators you can use in comparison:

Use them in boolean expressions, which return the output as a boolean value: True. If the condition holds or False otherwise.

For example:

12345
int x = 5; int y = 4; cout << (x > y) << endl; // will return true, because 5 is higher than 4 cout << (x <= 5) << endl; // will return true, because x is equal to 5 cout << ("hello" == "Hello"); // will return false, because these string aren't the equal
copy

The program returned 1 where the statement was true and 0 where was false.

question-icon
Check if the variable `x` is equal to the variable `y` and if `x` is greater than `450`.

#include
using namespace std;

int main() {
    int x = 24 * 25;
    int y = 19 * 32;
    cout << (x
y) << endl;
    cout << (x
450);
    return 0;
}
0
1

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1
some-alt