C Operators – Logical, Arithmetic, Relational – POFTUT

# C Operators – Logical, Arithmetic, Relational

[rps-include post=6557]

Operators are leg and arm of the C programming language. A lot of operations done with operators. Operators used to assign, sum, subtract, multiply, divide, remainder, increment, decrement … operations. We will look all of these operations in this chapter. Operators can be grouped like below.

• Arithmetic
• Relational
• Logical
• Bitwise
• Assignment
• Misc

# Arithmetic

Arithmetic is most popular usage of operators. Add, Subtract, Multiply, Divide, Modulus, Increment, Decrement operations can be done with arithmetic operators.

Add operator is `+` as expected. In the following example two numbers are added and assigned to a variable.

OR

## Subtract

As usual as subtraction we know which is  `-`

OR

## Multiply

Multiply operation can be done with `*` operator.

OR

## Divide

Divide operation can be done with `/` . The result can not decimal.

OR

## Modulus

Modulus operator will return the remainder or module operation result of two value.

OR

## Increment

Increment operator will increment given variable only.

OR

## Decrement

Decrement operation is the reverse of increment. Given variable will be decremented by one with `--` operator like below.

OR

# Relational

Relational operators generally used to compare two variables about their value. Below relational operators can be found.

## Equal

Equal operator will check values of given variables. If these values are equal `true` will be returned, if their values are not equal `false` will be returned. Equal operator is expressed as `==`

`(a == b)` will return true

`(a == b)` will return false

## Not Equal

Not equal operator is used to compare variables and return true if they are different, returns false if they are same. Not equal operator is expressed as `!=`

`(a != b)` will return true

`(a == b)` will return false

## Greater

Greater operator is used to test id one variable is greater  then other. Greater operator can be expressed with `>`

In this situation `a>b` will return false because `b` is greater than `a`

In this situation `a>`b will return true because a is greater than b

## Lower

Lower operator is used to test id one variable is lower  then other. Lower operator can be expressed with <

In this situation `a<b` will return true because `b` is lower than `a`

In this situation `a>`b will return false because a is lower than b

## Equal or Greater

Equal or Greater operator is similar to greater operator with addition to check equality with greatness. Equal or great will check if variables are equal or greater

This will return true because two variables are equal which is acceptable by our operator.

## Equal or Lower

Equal or Lower operator is similar to lower operator with addition to check equality with lowness. Equal or lower will check if variables are equal or lower

This will return true because two variables are equal which is acceptable by our operator.

# Logical

Logical operators are important part of decition making. They are generally used with if, for, while keywords where we will look next chapters in detail.

## And

And operator is a logical operator. And operator is expressed with `&&`

## Or

Or is a logical operator. Or operator can be expressed with `||`

## Not

Not operator is used with logic `true` and `false` . Not will revert given value

# Bit-wise

Bitwise operators are used to change variables with binary operations.

## Binary And

This operation will `And` two variables in a binary manner with their binary presentations.

## Binary Or

This operation will Or two variables in a binary manner with their binary presentations.

## Binary Xor

This operation will `Xor` two variables in a binary manner with their binary presentations.

## Binary One Complement

This operator will complement variables in binary form

## Binary Left Shift

This operator will shift specified step left the binary presentation of variable.

## Binary Right Shift

This operator will shift specified step right the binary presentation of variable.

# Assignment

Assignment is a popular operator used most of time for numerical operations.

[rps-include post=6557]