Another way to learn New Technology

0 622

# Operators in C Programming

## Relational Operators:

Relational operators are used to comparing the value of two variable for various conditions such as greater, less than or equal etc. All relational operator returns the result in either ‘True’ or ‘False’.
Following are some widely used relational operator in C Programming.

•     < less than
•     < = less than to equal to
•     > greater than
•     > = greater than or equal to
•     = = equal to
•     ! = not equal to

Below is the example showing result of some relational expressions.

12! = 15 True
12== = 12 True
46 > = 47 False
2.88 < = 3.10 True

## Logical Operators:

An expression, which combines two or more relational expression, is called logical expression. Just similar to the relational expression, logical expression results in either true or false.
Following are the logical operators used in the C program.

 Operator Action Names && AND Logical AND Operator || OR Logical OR Operator ! NOT Logical NOT Operator

The relational operators are self-explanatory. As far as the explanation of the logical operators is concerned, consider the following.

Any operator which uses two characters as a symbol should have no space between the two characters, that is = = is erroneous, if it is written as = =

The Logical AND Operator:

1.    Evaluates true, when both the relational expression are true.

2.    Evaluates false, when any one of the relational expression is false.

## Conditional Operator:

The C language has an unusual operator, useful for making two-way decisions. Is this operator a combination of? and: takes three operands. The general form of use of conditional operator is as follows:

Conditional expression? expression 1: expression 2

The conditional expression is evaluated first. If the result is nonzero, expression 1 is evaluated and is returned as the value of the conditional expression. Otherwise, expression 2 is evaluated and its value is returned.

For Example:

```if (x < 0) flag = 0;

else

flag= 1;

can be written as

flag = (x < 0) ? 0 : 1;
```