Operators in C Language

operators in c language
Operators are the symbol which operates on value or a variable. C language is rich in built-in operators and provides the following types of operators - 
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Other Operators

Arithmetic Operators

OperatorDescription
+Addition
-Subtraction
Multiplication
/Division
%Modulus/Remainder

Relational Operators

OperatorDescriptionExampleMeaning
>Greater thanx>yx is greater than y
<Less thanx<yx is less than y
>=Multiplicationx>=yx is greater than or equal to y
<=Divisionx<=yx is less than or equal to y
==Modulus/Remainderx==yx is equal to y
!=Modulus/Remainderx!=yx is not equal to y
  • Relational Operators are used to compare two numbers
  • if in a comparasion the condition is true then it returns 1.
  • if given condition is false then it returns 0.

Logical Operators

OperatorDescription
&&Logical AND
||Logical OR
!Logical NOT
Logical Operators works on Logic gates. The below table can help to understand how logic gate works in C Language.(False - 0, True - 1)
ABA&&BA||B!A
00001
01011
10010
11110

Bitwise Operators

Bitwise operator works on bits and performs bit-by-bit operation.
OperatorDescription
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~One's complement
>>Right Shift
<<Left Shift

Assignment Operators

OperatorDescriptionExample
=Assigns values from right side operands to left side operandc = a + b, in this statement value of a+b assigned into c
+=Add right operand to the left operand and then assign it to left operanda+=b is same as a=a+b
-=Subtract right operand from the left operand and then assign it to left operanda-=b is same as a=a-b
∗=Multiplies right operand with left operand and then assign it to left operanda∗=b is same as a=a*b;
/=Divides left operand with the right operand and then assign it to left operanda/=b is same as a=a/b
%=Calculate modulus using two operands and then assign it to left operanda%=b is same as a=a%b

Other Operators

OperatorDescriptionExample
sizeof()Returns size of variable.sizeof(i), if i is integer then it will return 4.
&Returns address of variable in memory.&i; will return address of the variable.
*Pointer variable.*i; will declare a pointer variable.
? :Conditional Operator
..

SHARE THIS
Previous Post
Next Post