Conditional Operator
Er Rohit Raman Ojha
AWS Certified Professional with Expertise in Solutions Architecture, Development, SysOps, Database Migration, Cloud Fundamentals, and email marketing expert at Ojha Softsolutions Private Limited with 30k Connections.
There is one more operator called conditional operator. This first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation. The conditional operator has this syntax ?
Show Examples
Operator Description Example
? : Conditional Expression If Condition is true ? Then value X : Otherwise value Y
Operators Categories
All the operators we have discussed above can be categorized into following categories ?Unary prefix operators, which precede a single operand.
Binary operators, which take two operands and perform a variety of arithmetic and logical operations.
The conditional operator (a ternary operator), which takes three operands and evaluates either the second or third expression, depending on the evaluation of the first expression.
Assignment operators, which assign a value to a variable.