What is a ternary operator?

0 votes
44 views
Shikhar Arora asked 07-Dec-2019 in Technology by Shikhar Arora

What is a ternary operator

1 Answer

0 votes
Sangsaptak Pal answered 11 days ago by Sangsaptak Pal
Often in a program there arrives where the triggering of a particular situation causes the execution of a particular set of statement and another set of execution for any other condition. This is the place where the use of a conditional statement arises. The ternary operator (?:) is nothing but just the compressed or the shorthand version of the conditional statements like if…. else.
The syntax is as follows:
Expression? (value if true): (value if false)
In this, if the expression evaluates to true then the first part is executed or else the second one. The expression is separated from the values with the question mark sign (?). The false and the true results are separated from each other by a colon sign (:).