**What is Operator**

**Ans**.: Operator used for perform operation on variable and value.

Type of Operator

- Arithmetic operators
- Comparision Operators
- Logical (or Relational ) Operators
- Assignment Operators
- Conditional (or Ternary) Operators

There are following Operator (suppos that A hold 15 and B hold 30)

## Arithmetic operators

+ Add two Operand A+B=45

– Subtract second operand from first A-B= -15

* Multiple both operand

/ Divide numerator by denumerator

% Modulus Operator and remainder of after an integer division

++ Increment operator, increases integer value by one

— Decrement operator, decreases integer value by one

**Example**

-$a :- Negative

$a + $b :- addition

$a – $b :- Subtract

$a * $b :- Multiplication

$a / $b :- Division

$a % $b :- Modulus

$a ** $b :- Exponentiation

## Comparison Operators

== Checks if the value of two operands are equal or not, if yes then condition becomes true.

!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true

> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true

< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true

>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true

<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

**Example **

$a==$b :- Equal

$a===$b :- Identical

$a!=$b :- NOT Equal

$a<>$b :- NOT Equal

$a!==$b :- NOT Identical

$a<$b :- Less Than

$a>$b :- Greater Than

$a<=$b :- Less Than Or Equal to

$a>=$b :- Greater Than Or Equal to

## Logical Operators

AND Called Logical AND operator. If both the operands are true then then condition becomes true. (A and B) is true.

OR Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (A or B) is true.

&& Called Logical AND operator. If both the operands are non zero then then condition becomes true. (A && B) is true.

|| Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (A || B) is true.

! Called Logical NOT Operator. Use to reverses the logical state of its operand. !(A && B) is false.

**Example**

$a AND $b

$a OR $b

$a XOR $b

! $a

$a && $b

$a || $b

## Assignment Operators

= Simple assignment operator, Assigns values from right side operands to left side operand (C=A+B).

+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand (C+=A)

-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand (C-=A)

*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand(C*=A)

/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand(C/=A)

%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand(C%=A)

## Conditional Operator (Ternary Operator)

? : Conditional Expression (A>B?25:20)

**Example**

$agestr = ($age < 16) ? ‘child’ : ‘adult’;