An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C language is rich in built-in operators and provides the following types of operators:

Arithmetic Operators

Following table shows all the arithmetic operators supported by C language. Assume variable A holds 10 and variable B holds 20, then:

Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiplies both operands A * B will give 200
/ Divides numerator by de-numerator B / A will give 2
% Modulus Operator and remainder of after an integer division B % A will give 0
++ Increments operator increases integer value by one A++ will give 11
-- Decrements operator decreases integer value by one A-- will give 9
Try the following example to understand all the arithmetic operators available in C programming language:
						include <stdio.h>
						main()
						{
						int a = 21
						int b = 10
						int c 
						c = a + b;
						printf("Line 1 - Value of c is %d\n", c )
						c = a - b
						printf("Line 2 - Value of c is %d\n", c )
						c = a * b;
						printf("Line 3 - Value of c is %d\n", c )
						c = a / b
						printf("Line 4 - Value of c is %d\n", c )
						c = a % b
						printf("Line 5 - Value of c is %d\n", c )
						c = a++
						printf("Line 6 - Value of c is %d\n", c )
						c = a--
						printf("Line7 - Value of c is %d\n", c )
						}
					

When you compile and execute the above program, it produces the following result:

Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 21
Line 7 - Value of c is 22

Relational Operators

Following table shows all the relational operators supported by C language. Assume variable A holds 10 and variable B holds 20, then:

Operator Description Example
== Checks if the values of two operands are equal or not,if yes then condition becomes true. (A == B) is not true.
!= Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true (A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.

Logical Operators

Following table shows all the logical operators supported by C language. Assume variable A holds 1 and variable B holds 0, then:

Operator Description Example
&& Called Logical AND operator. If both the operands are non-zero, then condition becomes true. (A && B) is false..
|| Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true. (A || B) is true.
! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false. !(A && B) is true.

Misc Operator

There are few other important operators including sizeof and ? : supported by C Language.

Operator Description Example
sizeof() Returns the size of an variable. sizeof(a), where a is integer, will return 4.
& Returns the address of an variable. &a; will give actual address of the variable.
* Pointer to a variable. *a; will pointer to a variable.
?: Conditional Expression If Condition is true ? Then value X : Otherwise value Y

Operators Precedence in C

Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator.
      For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

Operator Description Example
PostFix () [] -> . ++ - -> Left to Right
Unary + - ! ~ ++ - - (type)* & sizeof Right to left
Multiplicative * / % Left to Right
additive +- Left to Right
shift << >> Left to Right
Relational < <= > >= Left to Right
Equality == != Left to Right
Bitwise & ^ | Left to Right
Logical && || Left to Right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left