Operators in C


Operators
Operators are symbols, which are used to perform certain operations on data.
Arithmetic operators:
            Arithmetic operators are used to perform arithmetic operation on values.
·         Addition _____+
·         Subtraction_____-
·         Multiplication_____*
·         Division_____ /
·         Modulus_____%
Modulus is used to find the reminder of values. Contrary to the division operator, which returns the quotient, it returns the reminder of an integral division.
Relational operators:
            Relational operators are used to compare two values. These operators always evaluates to true or false.
·         Equal to_____==
·         Less than_____<
·         Greater than_____>
·         Less than or equal to_____<=
·         Greater than or equal to_____>=
·         Not equal to_____ !=
Logical operators:
            Logical operators combine two or more relational expressions to construct compound expression.
The logical operators are:
·         And_____&&
·         Or_____||
·         Not_____!

Assignment operators:
            Assignment operator is used to store a value or a computational result in a variable. In C = symbol represents the assignment operator.
Increment & decrement operators:
            The increment operator increases the value of the operand by one. It is donated by “++ “.
Example:
            count++;
It means that the new value of count is assign after the increment of 1 in the previous value of count.
 Prefix:
            When ++ precedes its operand is called prefix.
Example:
            j=10;
i=++j;
First assign the value of j that is 10. Second first the value of j is incremented by one the new value of j is 11. Then the result will be assigned to variable i. So, the values of i and j are 11.
            Postfix:
                        When the ++ follows its operand it is called postfix increment.
            Example:
                        j=10;
                        i=j++;
            In the second statement the value of j is assigned to variable i and then the value of j will be incremented. Hence the value of i is 10 and the value of j in the memory is 11.
Decrement:
            The decrement operator decreases the value of its operand by one.
It is donated by -- .
·         It can be use as either the prefix or postfix operator in the same way as the increment operator is used.

Note: Both the increment and decrement operator are unary operators.
Compound assignment operators:
                                          There are four other compound assignment operators that can increment or decrement the value of their operand by other than one.
·         +=
·         -=
·         *=
·         /=
Example:
 The statement j+=5; increase the value of j by 5, the statement j=-5; decrease the value of j by 5. Similarly we can use *= and /= operators.
Operator precedence:
Operator precedence determined its order of evaluation in an expression.

Operator
Precedence

Highest
 






lowest
!
*,  /,  %
+,  -
<,  <= ,  >,  >=
==,  !=
&&
||
=
                                                                                                                                               

Comments

Popular Posts