Contenido del Curso
Introduction to C++
Introduction to C++
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:
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
The program returned 1
where the statement was true and 0
where was false.
¡Gracias por tus comentarios!