PDA

View Full Version : Relational and equality operators ==, !=, >, <, >=, <= in c++ May 2011



Vuhelper
05-29-2011, 06:22 PM
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Here there are some examples:

1
2
3
4
5
(7 == 5) // evaluates to false.
(5 > 4) // evaluates to true.
(3 != 2) // evaluates to true.
(6 >= 6) // evaluates to true.
(5 < 5) // evaluates to false.

http://t1.gstatic.com/images?q=tbn:ANd9GcTc12vySquaWLNDNys7hesTCqSsmgeaV 50bEt3_9GqIutcOGnrzaA
Of course, instead of using only numeric constants, we can use any valid expression, including variables. Suppose that a=2, b=3 and c=6,

1
2
3
4
(a == 5) // evaluates to false since a is not equal to 5.
(a*b >= c) // evaluates to true since (2*3 >= 6) is true.
(b+4 > a*c) // evaluates to false since (3+4 > 2*6) is false.
((b=2) == a) // evaluates to true.