Operators in C Programming



Arithmetic Operators

Most C programs perform calculations using the C arithmetic operators. Note the use of various special symbols not used in algebra.

C Operation Arithmetic Operator Algebraic Expression C Expression
Addition + a + 10 a + 10
Subtraction - k - p k - p
Multiplication * bm b * m
Division / x/y or x:y x / y
Remainder % r mod h r % h

Precedence of Arithmetic Operators

The rules of operator precedence specify the order C uses to evaluate expressions.

Operator(s) Operation(s) Order of evaluation (precedence)
() Parentheses Evaluated first. If the parentheses are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses "on the same level", they are evaluated left to right.
* Multiplication Evaluated Second. Left to right if there are several.
/ Division
% Remainder
+ Addition Evaluated Third. Left to right if there are several.
- Subtraction
= Assigment Evaluated last.

Equality and Relational Operators

Algebraic equality or relational operator C equality or relational operator Example of C condition Meaning of C condition
Equality operators
= == a == b a is equal to b

!= a != b a is not equal to y
Relational Operators
< < a < x is less than y
> > a > b a is greater than b
>== a >== b a is greater than or equal to b
<== a <== b a is less than or equal to b

Logical Operators

Operator Meaning of Operator Example
&& Logial AND If c=5 and d=2 then,((c==5) && (d>5)) returns false.
|| Logical OR If c=5 and d=2 then, ((c==5) || (d>5)) returns true.
! Logical NOT If c=5 then, !(c==5) returns false.

Bitwise Operators

Operators Meaning of operators
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
~ Bitwise complement
<< Shift left
>> Shift right

PROMOTIONS