# Operators in C

An operator is an image that tells the compiler to carry out unique math or good judgment functions. C language is wealthy in integrated operators and presents the subsequent forms of operators âˆ’

## The Different Types Of Operators in C

1. Arithmetic Operators

Simple operations of arithmetic are addition, subtraction, multiplication and division.

Operator Description Example
+

It adds two operands. X + Y
â€“

(subtraction)

It subtracts the second operand from the primary. X â€“ Y
*

(multiplication)

It multiplies both operands. X * Y
/

(division)

It Divides the numerator by denominator. X / Y
%

(remainder)

It gives the remainder after an integer division. Y % X
++ It will increase the integer cost through one. X++
â€” It will decrease the integer cost through one. Xâ€“

2. Relational Operators

Let us assume that variable X holds the worth of 20 and variable B holds 30. Below the table, let us see how relational operator works:-

Operator Description Example
== If the values of two operands are equal, then the condition becomes true. (X == Y) is not true.
!= If the values of two operands are not equal, then the condition becomes true. (X != Y) is true.
> If the worth of the left operand is bigger than the worth of the right operand, then the condition becomes true. (X > Y) is not true.
< If the worth of the left operand is a smaller amount than the worth of the right operand, then the condition becomes true. (X < Y) is true.
>= If the worth of the left operand is bigger than or adequate to the worth of the right operand, then the condition becomes true. (X >= Y) is not true.
<= If the worth of the left operand is less than or adequate to the worth of the right operand, then the condition becomes true. (X <= Y) is true.

3. Logical Operators

The following table suggests all of the logical operators supported with the aid of using the C language. Assume variable A holds 1 and variable B holds 0, then:-

Operator Description Example
&&

(Logical AND Operator)

If each of the operands is non-zero, then the situation will become true. (A && B) is false.
||

(Logical OR Operator)

If any of the two operands are non-zero, then the condition becomes true. (A || B) is true.
!

(Logical NOT Operator)

It is used to opposite the logical kingdom of its operand. If a condition is true, then the Logical NOT operator will make it false. !(A && B) is true.

4. Bitwise Operators

The bitwise logical operators study one bit at a time of their operands and compute the corresponding bit price withinside the result.

During calculation, arithmetic operations such as addition, subtraction, multiplication, and division are converted to the bit level, speeding up processing and saving power. The bitwise logical operators are used in C programming to perform bit-level operations.

Here is a table showing how the bitwise logical operators are evaluated.

X y x & y x | y x ^ y
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0

There are six different types of bitwise logical operators in the C language:

Bitwise logical operators Description
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
~ Bitwise complement
<< Shift left
>> Shift right

5. Assignment Operators.

The assignment operator is used to assigning the values for the variables in C programs. The following desk indicates assignment operators supported in C.

Operator Description Example
=

(assignment)

Assigns values from proper facet operands to left facet operand Z = X + Y will assign the value of

X + Y to Z

+=

It adds the right operand to the left operand and assigns the result to the left operand. Z += X is equivalent to Z = Z + X
-=

(Subtract AND)

It subtracts the proper operand from the left operand and assigns the result to the left operand. Z -= X is equivalent to Z = Z â€“ X
*=

(Multiply AND)

It multiplies the right operand with the left operand and assigns the result to the left operand. Z *= X is equivalent to Z = Z * A
/=

(Divide AND)

It divides the left operand with the proper operand and assigns the result to the left operand. Z /= X is equivalent to Z = Z / X
%=

(Modulus AND)

It takes modulus using two operands and assigns the result to the left operand. Z %= X is equivalent to Z = Z % X

6. Misc Operators

Misc Operators In addition to the above operators, a few critical operators are supported withinside the C language.

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

Operators Precedence in C

Operator precedence determines the term group of an expression and how it evaluates the expression. Certain operators have a higher priority than other operators. For example, the multiplication operator has higher precedence than the addition operator. The expression evaluates the operator with the highest priority first.

Category Operator Associativity
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 AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left
Comma , Left to right

How to use operators in a C program

Below are some examples that will help us know how do operators function in C programming.

Arithmetic Operator

INPUT :

OUTPUT :

Relational Operator

INPUT :

OUTPUT :

Logical Operators

INPUT :

OUTPUT :

Bitwise Operators

INPUT :

OUTPUT :

Misc Operators.

INPUT :

OUTPUT :

Why should you learn how to use operators?

Because itâ€™s the fastest way of executing code at the lowest possible level.

int x = 5 * 4 + 3;

is nicer than:

• int x;
• x.assign ( int(5).mul(int(4)).add(int(3)) );Each time you name a procedure, you command the CPU to jump from one deal to another in the computerâ€™s memory; it has to save the popularity of the preceding operations every time. Answering your question: itâ€™s very stressful and the maximum inopportune manner to remedy an easy mathematics operation.

#### Vaibhav Kapoor

A professional web entrepreneur, WordPress developer and digital marketing strategist with more than 4 years of experience in building a business from scratch. Knowledgeable about SEO, blogging, internet marketing, social media and website development.

[wpfepp_submission_form form="1"]