# C Operators

C Operators are used to making `mathematical or logical `computations in the program.

These are of the following eight types -

1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Assignment Operator
5. Increment & Decrement Operator
6. Conditional Operator
7. Bitwise Operator
8. Other Operator

### Arithmetic Operators

With the help of these c operators, simple `calculations` like addition, subtraction, multiplication, and division, etc. can be done. These are of two types. Binary and Unary.

Binary Operators - Two operands or two numbers are required to use `binary` operators.

Operator Explanation
Addition (`+`) It is used to perform basic and simple addition.
Subtraction (`-`) It is used to perform basic and simple subtraction.
Multiply (`*`) It performs basic multiplication.
Division (`/`) It performs simple division.
Modulus (`%`) It returns the remainder.

Unary Operators - One operand or one number are required to use `unary` operators.

Operator Explanation
Plus (`++`) Increase value by 1
Minus (`--`) Decrease value by 1

### Relational Operators

Sometimes we need to check the relation between two numbers. On the basis of this `relationship`, other calculations are based. For this, we use relational operators.

There are 6 types of relational operators –

Operator Meaning
< is less than
<= is less than or equal to
> is greater than
>= is greater than or equal to
== is equal to
!= is not equal to

They are generally used with decision statements like `if` or loop statements like `while` etc.

### Logical Operators

Logical operators are used to checking more than one condition. These are of three types -

Symbol Explanation
Logical AND (`&&`)

The logical operator `&&` is used between two conditions when we have to check that both are true.

Logical OR (`||`)

Logical operator `||` is used between two conditions when we have to check whether one of the two is true or not.

NOT (`!`)

Logical operator `!` is used for the opposite meaning.

### Assignment Operators

It is used to assign a value to a variable or to store the remaining value in a variable after solving an expression.

Its general syntax is as follows –

Variable = expression/value

Operator Explanation
Assign (`=`) `=` j  The left operand gets set to the value of the expression on the right
Add then Assign (`+=`) `+=` j or i = i + j
Subtract then Assign (`-=`) `-=` y or i = i – j
Multiply then Assign (`*=`) `*=` y or i = i * j
Divide then Assign (quotient) (`/=`) `/=` y or i = i / j
Divide then Assign (remainder) (`%=`) `%=` y or i = i % j

### Increment/Decrement Operator

In 'C' programs, two important operators `++` and `--` are used to add or subtract 1 respectively to the value of any variable.

Both of them come under the category of Unary Operators.

They are used in the following two ways.

Operator Explanation
x++ post `increment`
++x `pre` increment
x-- post `decrement`
--x `pre` decrement

Using the operator after in a variable means that the value is to be incremented after the statement is `executed` or using operator first means that the statement should be executed by doing `increment` first.

### Conditional Operator

This c operator is used to check whether a condition is true or false and to make a `decision` based on the condition.

It is a ternary operator and requires `three` operands to be used.

Its general syntax is as follows –

Condition ? value1 : value2;

### Bitwise Operators

It performs bit-level operations and requires two numbers or two operands to use.

Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise `Exclusive` OR
~ Bitwise Complement
<< Left `Shift`
>> `Right` Shift

### Other Operators

The sizeof operator

The `sizeof` is a unary operator, returns the size of a variable.

Comma Operator

Will be discussed in later tutorials.