It is a ternary operator because it uses the condition, a and b i.e. If condition is true,then a is assigned to x else b is assigned to x. Then, after y=x++ y=10 and x=11, this is because x is assigned to y before its increment.īut if we had written y=++x y=11 and x=11, because x is assigned to y after its increment.Ĭonditional Operator: It is similar to if-else: Unary operators are the operators which require only one operand. Increment/Decrement Operators: These are unary operators. Shifts the value of x by y bits towards the right and stores the result back in x. Takes modulus using the two operands and assigns the result to the left side operand. Multiplies the right side operand with the left side operand and assigns the result to the left side operand.ĭivides the left side operand with the right side operand and assigns the result to the left side operand. Subtracts the right side operand from the left side operand and assigns the result to the left side operand.
Returns true if x is false else returns false.Īssigns value from the right side operand(s) to the left sideĪdds the right side operand to the left side operand and assigns the result to the left side operand. Returns false if neither x nor y is true else returns true Returns true if both x and y are true else returns false. Note: In C,C++ any non-zero number is treated as true and 0 as false but this doesn't hold for Java. Logical Operators: These operators take boolean values as input and return boolean values as output. Notice, the bits are shifted 2 units to the right and the new bits are filled by 0s.įor more information about how these operators work, see : Bit Manipulation The left operand's value is moved right by the number of bits specified by the right operand.It is equivalent to dividing x by $$2^y$$ Greater than or equal to the value of the right operand, if yes then condition becomes true. Greater than the value of the right operand, if yes then condition becomes true The relational operators are as follows:Įqual or not, if yes then condition becomes true.Įqual or not, if values are not equal then condition becomes true.Ĭhecks if the value of the left operand is
The operator '=' should not be confused with '='. They return either true or false based on the comparison result. Relational Operators: These operators are used for comparison. Multiplies values on either side of the operatorĭivides the left hand operand by the right hand operandĭivides the left hand operand by the right hand operand and returns remainder Subtracts the right hand operand from the left hand operand In this tutorial, we will try to cover the most commonly used operators in programming.Īdds values on either side of the operator Operators are symbols that tell the compiler to perform specific mathematical or logical manipulations.