C ++ブール式
ブール式
ブール式は、ブール値1
(true)または0
(false)を返すC ++式です。
大なり記号( )演算子などの比較演算子を使用して>
、式(または変数)が真であるかどうかを確認できます。
例
int x = 10;
int y = 9;
cout << (x > y); // returns 1 (true), because 10 is higher than 9
またはさらに簡単:
例
cout << (10 > 9); // returns 1 (true), because 10 is higher than 9
以下の例では、equal to(==
)演算子を使用して式を評価します。
例
int x = 10;
cout << (x == 10); // returns 1 (true), because the value
of x is equal to 10
例
cout << (10 == 15); // returns
0 (false), because 10 is not equal to 15
ブール値は、すべてのC ++の比較と条件の基礎です。
次の章で、条件(if ... else)について詳しく学習します。