Ternary Operator can also be used in Lvalue in C++ programming language

Vivek Vijayan
Aug 29, 2022

Operators in CPP

As we all known and used ternary operator (Conditional operator)(?:) in the rvalue of the assignment statement, which assign the true statement value to the lvalue or else false statement value if condition fails.

rvalue ternary operator

But similarly, we can also use the same functionality in the lvalue side of the assignment operator too. Based on the condition, the ternary operator determines which lvalue variable should hold the value.

This concept can be used if our program needs a decision to be taken which variable to hold the resultant value.

lvalue ternary operator

Checkout my sample code to explain this concept

Conclusion

Thanks for reading, hope this blog helps.

Stay connected

LinkedIn * Github * Medium

--

--

Vivek Vijayan

I’m a Computer Science Engineer, IoT Expert and Full stack developer, helping programmers in getting their projects fulfilled