C Operator





Operators are symbols that act upon data. They represent a particular operation to be performed on the data. operators can be classified in the following categories.


Arithmetical Operators : The arithmetic operator perform arith metic operations on any built in data type.
Operator                        Function
+                                    Addition
-                                    Subtraction
x                                    Multiplication
/                                    Divison
^                                    Exponentiation
%                                  Modulus (Remainder)

Special Arithmetic Operator
++                              increment
--                               decrement
X ++ or ++ X  is equivalent to X = X+1
Similarly
X -- or -- X is equivalent to X= X-1

Relational Operators
: These operator are  used to compare two values on the basis of a certain condition.

Operator                   Function
<                               Less than
< =                            Less than equal to
>                              Greater than
>=                            Greater than equal to
!=                             Not equal to
==                            Equal to

Logical Operator : These operator are used to perform logical operations
Operator              Function
& &                      AND
||                          OR
!                          NOT

Assigning Operator : These operator are used assign values to variables.
Operator                  Function
=                              Assign Value
+=                            Add the values and assign it to the left
-=                            Subtract the values and assign it to the left
*=                            Multiply the Values and assign it to the left
/=                            Divide the values and assign it to the left
%=                          Find the remainder and assign it to the left 

Ternary Operator : These operator are very powerful operator in 'C'. In some cases, it is equivalent to the "if" - else statement .

Operator "?" and ":"

Syntax => expression = exp 1 ? exp 2: exp 3;

Example : a= 50; b= a> 100 ? 25:35;
Here the value of b will be 35 because a is less than 100 and the condition is false.