Booleans
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:
12345int 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
The program returned 1
where the statement was true and 0
where was false.
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Запитайте мені питання про цей предмет
Сумаризуйте цей розділ
Покажіть реальні приклади
Awesome!
Completion rate improved to 3.33
Booleans
Свайпніть щоб показати меню
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:
12345int 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
The program returned 1
where the statement was true and 0
where was false.
Дякуємо за ваш відгук!