 # Operators In C

C has a rich set of operators (i.e., things like + – * / ), which allow you to write complicated expressions quite compactly. General expressions are formed by joining together constants and variables (operands) via various operators.

Operators in C fall into a number of classes:

Arithmetic operators, Unary operators, Relational and Logical operators, Assignment operators, Equality operators, and the Conditional operator.\

## Unary Operators

Unary operators are operators that only take one argument.

```+123  positive 123
-123  negative 123
!i    logical negation (i.e., 1 if i is  zero, 0 otherwise)
++i   adds one to i, and returns the new value of i
––i   subtracts one from i, and returns the new value of i
i++   adds one to i, and returns the old value of i
i– –  subtracts one from i, and returns the old value of i ```

## Binary Operators

Binary operators work on two operands (‘binary‘ here means 2 operands, not in the sense of base-2 arithmetic).

```+   addition
–   subtraction
*   multiplication
/   division
%   remainder (e.g., 2%3 is 2), also called  'modulo'
<<  left-shift (e.g., i<<j is i shifted to the left by j bits)
>>  right-shift
&   bit wise AND
|   bit wise OR
^   bit wise exclusive-OR
&&  logical AND (returns 1 if both operands are non-zero; else 0)
||  logical OR (returns 1 if either operand is  non-  zero; else 0)
<   less than (e.g., i<j returns 1 if i is less than j)
>   greater than
<=  less than or equal
>=  greater than or equal ==   equals
!=  does not equal
?   conditional operator ```

## Assignment Operators

The most common assignment operator in C is the equals operator, =. It is used to change the value of a variable. For instance, the expression:  f = 3.4; causes the floating-point value 3.4 to be assigned to the variable f.

Multiple assignments are permissible in C. For example,

i = j = k = 4;

causes the integer value 4 to be assigned to i, j, and k, simultaneously.

Assignment operators are really just binary operators.

```=   assignment
-=  subtraction assignment
*=  multiplication assignment
/=  division assignment
%=  remainder/modulus assignment
&=  bit wise AND assignment
|=  bit wise OR assignment
^=  bit wise exclusive OR assignment
<<= left shift assignment
>>= right shift assignment ```

## Arithmetic Operators

There are four main arithmetic operators in C:

```   addition         +
subtraction      –
multiplication   *
division         /  ```

There is no built-in exponentiation operator in C . Instead, there is a library function (pow) which carries out this operation.

e.g. x2 is represented as x * x

## Relational Operators

Relational operators are used to compare two or more operators. The result of comparison is either true or false.

## Logical Operators

Effects  on relational expression’s results also AND, OR combines two or more Relational expressions,  Results will be returned either TRUE( 1 ) or FALSE ( 0 ) regards with specific situations.

Suppose we have the following values:

a =  2, b = 5, c = 9, d = 7

Get The Coding Examples From C Language Code Example Page

## Code Example

Support us by sharing this post