Description
Description
Operators | Operator | Description | Example |
|---|---|---|
| + | Adds two operands | x+y gives 30 |
| - | Subtracts second operand from the first | x-y gives -10 |
| * | Multiplies operands | x*y gives 200 |
| / | Divide numerator by denominator | x/y gives 2 |
| % | Modulus operator gives remainder after an integer division | y%x gives 0 |
| ++ | Increment operator: Increases integer value by one | x++ gives 11 |
| -- | Decrement operator: Decreases integer value by one | x-- gives 9 |
Examples
Description
Operators | Operator | Description | Example |
|---|---|---|
| = | Assignment Operator: Assigns right-hand side value (called rvalue) to left-hand side(called lvalue) value. | z=x+y assigns value of x+y into z |
| += | Add AND Assignment Operator: Adds right operand to left operand and assigns the result to left operand. | y+=x is equivalent to x=y+x |
| -= | Subtract AND Assignment Operator: Subtracts right operand from left operand and assigns the result to left operand | y-=x is equivalent to y=y-x |
| *= | Multiply AND Assignment Operator: Multiplies right operand with left operand and assigns the result to left operand | y*=x is equivalent to x=y*x |
| /= | Divide AND Assignment Operator: Divides right operand by left operand and assigns the result to left operand | y/=x is equivalent to x=y/x |
| %= | Modulus AND Assignment Operator: Takes modulus using two operands and assigns the result to left operand | y%=x is equivalent to x=y%x |
| <<= | Left shift AND Assignment Operator | y<<=2 is same as y=y<<2 |
| >>= | Right shift AND Assignment Operator | y>>=2 is same as y=y>>2 |
| &= | Bitwise AND Assignment Operator | y&=2 is same as y=y&2 |
| ^= | Bitwise Exclusive OR and Assignment Operator | y^=2 is same as y=^2 |
| |= | Bitwise Inclusive OR and Assignment Operator | y|=2 is same as y=y|2 |
Examples
Description
Operators | Operator | Symbol | Form | Operation |
|---|---|---|---|
| Right shift | >> | x>>y | all bits in x shifted to the right y bits |
| Left shift | << | x<<y | all bits in x shifted to the left y bits |
| Bitwise AND | & | x&y | each bit in x AND each bit in y |
| Bitwise OR | | | x|y | each bit in x OR each bit in y |
| Bitwise XOR | ^ | x^y | each bit in x XOR each bit in y |
| Bitwise NOT | ~ | ~x | all bits in x flipped |
Example
Description
Operators | Operator | Description |
|---|---|
| == | Checks if the value is equal or not. If yes, then returns true. |
| != | Checks if the value is equal or not. If the values are not equal, then the condition becomes true |
| > | Checks for greater value |
| < | Checks for lower value |
| >= | Checks if the value is greater than or equal to the value |
| <= | Checks if the value is less than or equal to the value |
Example
Description
Operators | Operator | Name of Operator | Output |
|---|---|---|
| && | AND Operator | Output is 1 only when conditions on both sides of the operator becomes true |
| || | OR Opeator | Output is 0 only when conditions on both sides of the operator becomes false |
| ! | NOT Operator | Gives inverted output |
Example
Key Points