Operators


    

    

Arithmetic Operators

Arithmetic operators are used to perform common mathematical operations.

Operator Name Description Example
+ Addition Add two values together a + b
- Subtraction Subtract one value from another a - b
* Multiplication Multiplies two values a * b
/ Division Divides one value by another a / b
% Modulus Returns the division remainder a % b
++ Increment Increase the value by 1 a ++
-- Decrement Decrease the value by 1 a - -

Assignment Operators

Assignment operators are used to assign a value to a variable.

Operator Example Meaning
= a = 5 a = 5
+= a += 5 a = a + 5
-= a -= 5 a = a - 5
*= a *= 5 a = a * 5
/= a /= 5 a = a / 5
%= a %= 5 a = a % 5
&= a &= 5 a = a & 5
|= a |= 5 a = a | 5
^= a ^= 5 a = a ^ 5
>>= a >>= 5 a = a >> 5
<<= a <<= 5 a = a << 5

Comparison Operators

Comparison operators help us to compare two values to determine if the value is true or false. These operators will return the value of the comparison in a boolean value.

Operator Name Example
== equal to x == y
!= not equal to x != y
> greater than x > y
< less than x < y
>= greater than or equal to x >= y
<= less than or equal to x <= y

Logical Operators

Logical operators are used to determine the logic between variables or values. These operators also return a boolean value (true or false).

Operator Name Description Example
&& logical AND returns true if all statements are true x < 10 && x > 3
|| logical OR returns true if one of the statements is true x > 100 || x < 30
! logical NOT return false if the statement is true and vice versa !(x > 100 || x < 30)

Bitwise Operators

Bitwise operators are operators that operate numbers on bit-level operation.

Operator Name Example
& bitwise AND x & y
| bitwise OR x | y
^ bitwise XOR x ^ y
<< bitwise left shift x << y
>> bitwise right shift x >> y
~ bitwise NOT ~x