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.
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 3.33
Booleans
Svep för att visa menyn
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.
Tack för dina kommentarer!