What are the different operators?



Arithmetic operators: 

The arithmetic operators are +, -, *, /. They work the same way as they do in other languages. There are three types of arithmetic operators which are as follows,




.

Integer arithmetic: 

Here operands are integer. For a=14 and b=4,
                                   a + b = 18        
                                   a / b = 3 (decimal part)          
                                   a % b = 2 (remainder of division)

Real arithmetic: 

Here, operands are only real number. Such as, if a=6.0 and b=7.0 then a/b=0.857143


Mixed model arithmetic: 


Here, one operand is real and another is integer. Such as,15/10.0=1.5 Whereas,15/10=1

Relational operators : 

The operators which are used to compare two numbers and take decision depending on their relation are called relational operators. Some relational operators are

Operator
Meaning
< 
Is less than
<=
Is less than or equal
> 
Is greater than
>=
Is greater than or equal
==
Is equal to
!=
Is not equal to

Logical operators: 

Operators which are used to combine two or more relational expressions are known as logical operators. There are three logical operators. They are,

                  &&              meaning logical            AND
                   ||                 meaning logical            OR
                   !                  meaning logical            NOT

Assignment operators:

Operators which are used to assign the result of an expression to a variable are known as assignment operators. Consider an example,        

               x  +=  (y+1)

The operator += means ‘add y+1 to x’ or ‘increment x by y+1’. For y=2, the above statement results,   x  +=  3, that is (x = x + 3)

ContentMiddleAd                       

Increment and Decrement operators:

C allows two very useful operators not generally found in other languages. These are the increment and decrement operators, respectively ++ and --. The operator ++ adds 1 to the operand, while -- subtracts 1. There are some rules there for using ++ and -- operator.

Conditional operators: 

A ternary operator pair “ ? : ” is available in C to construct conditional expressions of the form exp1?exp2:exp3. The operator works as follows, exp1 is evaluated first. If it is nonzero (true) then the expression exp2 is evaluated and becomes the value of the expression. If exp1 is false, then exp3 is evaluated and becomes the value of the expression. For example, consider the following statements,

                          a = 10;
           b = 15;
           x = (a > b) ? a : b;

In this example x will be assigned the value of b.

Bitwise operators:

Operators which are used to manipulate data at their bit level are known as bitwise operators. Bitwise operators and their meanings are given below,

Operator
Meaning
&
Bitwise AND
|
Bitwise OR
^
Bitwise exclusive OR
<< 
Shift left
>> 
Shift right

Special operators:

C supports some special operators of interest such as comma operator, sizeof operator, pointer operators (& and *) and member selection operators (. And ->).

Recommended Recommends

Comments

Contact Us