There is also a short-hand if else, which is known as the ternary operator because it consists of three operands.It can be used to replace multiple lines of code with a single line, and is most often used to replace simple if else statements:...
Ternary Operator The ternary operator is a simplified conditional operator likeif/else. Syntax:condition ? <expression if true> : <expression if false> Here is an example usingif/else: ExampleGet your own React.js Server Before: if(authenticated){renderApp();}else{renderLogin();} ...
Related Resources Does Python have a ternary conditional operator? Reference — What does this symbol mean in PHP? How can I prevent SQL injection in PHP? Submit Do you find this helpful? YesNo About Us Privacy Policy for W3Docs Follow Us...
You can simply write: Example inttime =20; string result = (time <18) ?"Good day.":"Good evening."; cout << result; Try it Yourself » Exercise? What is the ternary operator in C++? A short-hand way of writing if...else statements ...
There is also a short-hand if else, which is known as theternary operatorbecause it consists of three operands. It can be used to replace multiple lines of code with a single line. It is often used to replace simple if else statements: ...