Conditions
In computer science, conditional statements,
conditional expressions and conditional constructs are features of a
programming language, which perform different computations or actions depending
on whether a programmer-specified boolean condition
evaluates to true or false.
Relational Operators
Relational
operators are used to find the relation between two variables. i.e. to compare
the values of two variables in a C program.
|
Operators |
Example/Description |
|
> |
x > y (x is greater than y) |
|
< |
x < y (x is less than y) |
|
>= |
x >= y (x is greater than or
equal to y) |
|
<= |
x <= y (x is less than or equal
to y) |
|
== |
x == y (x is equal to y) |
|
!= |
x != y (x is not equal to y) |
The following table shows all the
relational operators supported by C language. Assume variable A holds 10
and variable B holds 20 then −
|
Operator |
Description |
Example |
|
== |
Checks
if the values of two operands are equal or not. If yes, then the condition
becomes true. |
(A
== B) is not true. |
|
!= |
Checks
if the values of two operands are equal or not. If the values are not equal,
then the condition becomes true. |
(A != B) is true. |
|
> |
Checks
if the value of left operand is greater than the value of right operand. If
yes, then the condition becomes true. |
(A
> B) is not true. |
|
< |
Checks
if the value of left operand is less than the value of right operand. If yes,
then the condition becomes true. |
(A
< B) is true. |
|
>= |
Checks
if the value of left operand is greater than or equal to the value of right
operand. If yes, then the condition becomes true. |
(A
>= B) is not true. |
|
<= |
Checks
if the value of left operand is less than or equal to the value of right
operand. If yes, then the condition becomes true. |
(A
<= B) is true. |
Logical
Connectives
|
Operators |
Example/Description |
|
&& (logical AND) |
(x>5)&&(y<5) |
|
|| (logical OR) |
(x>=10)||(y>=10) It returns true when at-least one
of the condition is true |
|
! (logical NOT) |
!((x>5)&&(y<5)) It reverses the state of the
operand “((x>5) && (y<5))” If “((x>5) &&
(y<5))” is true, logical NOT operator makes it false |