Home > Electronics Tutorials > C Language Tutorial > Operators - Normal

C Language Programming Library Reference Guide

Operators - Normal

There are several normal operators which return the result defined for each: expression1 + expression
The result of this is the sum of the two expressions.

expression1 - expression2
The result of this is the value of expression2 subtracted from expression1.

expression1 * expression2
The result of this is the value of expression1 multiplied by expression2.

expression1 / expression2
The result of this is the value of expression1 divided by expression2.

expression1 % expression2
The result of this is the value of the remainder after dividing expression1 by expression2. Also called the modulo operator.

expression1 & expression2
Returns a bitwise AND operation done on expression1 and expression2. The result is a value the same size as the expressions with its bits modified using the following rules: Both bits must be 1 (on) to result in 1 (on), otherwise the result is 0 (off).
 
e1 e2 Result
0 0 0
0 1 0
1 0 0
1 1 1

expression1 | expression2
Returns a bitwise OR operation done on expression1 and expression2. The result is a value the same size as the expressions with its bits modified using the following rules: Both bits must be 0 (off) to result in 0 (off), otherwise the result is 1 (on).
 
e1 e2 Result
0 0 0
0 1 1
1 0 1
1 1 1

expression1 ^ expression2
Returns a bitwise XOR operation done on expression1 and expression2. The result is a value the same size as the expressions with its bits modified using the following rules: If both bits are the same, then the result is 0 (off), otherwise the result is 1 (on).
 
e1 e2 Result
0 0 0
0 1 1
1 0 1
1 1 0

expression1 >> shift_value
Returns expression1 with its bits shifted to the right by the shift_value. The leftmost bits are replaced with zeros if the value is nonnegative or unsigned. This result is the integer part of expression1 divided by 2 raised to the power of shift_value. If expression1 is signed, then the result is implementation specific.

expression1 << shift_value
Returns expression1 with its bits shifted to the left by the shift_value. The rightmost bits are replaced with zeros. This result is the value of expression1 multiplied by the value of 2 raised to the power of shift_value. If expression1 is signed, then the result is implementation specific.
Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Discover

     more......