C ++比較演算子


比較演算子

比較演算子は、2つの値を比較するために使用されます。

注:比較の戻り値は、true(1)またはfalse(0)のいずれかです。

次の例では、大なり記号演算子()を使用して、5が3より大きいかどうかを確認します>

int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3

すべての比較演算子のリスト:

Operator Name Example Try it
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

比較演算子とその使用方法については、後の章で詳しく説明します。