In this tutorial you will familiarize with the various types of operators which are available for the c programming language.
Operators in C language:
An operator in C is defined as a sign or symbol that tells the compiler to implement definite mathematical or logical operation.
C language has numerous built-in operators and offers the following types of operators.
Types of operators:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bit-wise Operators
- Assignment Operators
Let us discuss all the operators in succession:
- Arithmetic Operators :Elementary arithmetic operations comprises addition(+),subtraction(-), division(/),multiplication(*),modulus(%).The following table demonstrates all the arithmetic operators supported by the C language.
Assume variable X=25 and Y=5 then
Operator Description Example + Adds both the operands X+Y =30 - Subtracts second operand from the first operand X-Y = 20 * Multiplies both operands X*Y = 125 / Divides numerator by denomenator X/Y = 5 % Calculates remainder of after division X%Y = 0
- Relational Operators : The following table shows all the relational operators supported by C. Assume X=10 and Y=20
Operator Description Example == Compares the condition that values of two operands are equal. (X == Y) is not true. != Compares the condition that values of two operands are not equal. (X != Y) is true. > Checks the condition that value of left operand is more than the value of right operand. (X > Y) is true. < Checks the condition that value of left operand is lesser than the value of right operand. (X < Y) is not true. >= Checks the condition that value of left operand is more than or equal to the value of right operand. (X >= Y) is true. <= Checks the condition that value of left operand is less than or equal to the value of right operand. (X <= Y) is not true.
- Logical Operators :Following table shows all the logical operators supported by C language. Assume variable A = 1 and B = 0, then −
Operator Description Example (&&) If both the operands are non-zero; then the condition becomes true (A && b) is false. | | If any of the two operands is non-zero; then the condition becomes true (A || B) is true. ! If a condition is true then Logical NOT operator will make it false.!(A && B) is true.
- Bit-wise operator:
Bitwise operator works on bits and perform bit-by-bit operation.this operations are as follows−
& : AND operator , this operator performs ANDing of two bits.
p q p & q p | q p ^ q ~p ~q 0 0 0 0 0 1 1 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1 1 1 1 0 0 0
| : OR operator , this operator performs ORing of two bits.
^ : XOR operator , this operator performs XORing of two bits.
~ : NOT operator , this operator performs complement of a given number.
- Assignment Operators :
Operator Description Example = Assigns values from right side operands to left side operand C = A + B will assign the value of A + B to C
This is all about the available operators in C. For any query please comment below.