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)について詳しく学習します。


C ++演習

エクササイズで自分をテストする

エクササイズ:

不足している部分を入力して、値1(trueの場合)および0(falseの場合)を出力します。

 isCodingFun = true;
 isFishTasty = false;
cout << ;
cout << ;