You're right.
In C ++, there are situations of conditional assignment when using an if-else statement is not possible, since this language clearly distinguishes between initialization and assignment.
In addition, the ternary operator can give the value l, that is, a value to which another value can be assigned.
In addition, some compilers in some cases may generate different code for ternary vs conditional if-then. GCC, for example, performs better code optimization if the ternary operator is used.
See also ?: Ternary operator in C ++ .
user405725
source share