[Solved] How to write one line and nested ‘if’ statement without ‘?:’ (is it possible?)


You already used the two important words that are key to undestand why what you intend is not possible, but you probably haven’t grasped their full meaning: Statement and expression.

The if statement (like all statements) does not yield a value, while the ?: operator is an expression that does yield a value.

Distinguishing between statements and expressions is a fundamental concept that is worth learning (check out the links in this answer and take your time!), not just for C++ but for almost all programming languages.

4

solved How to write one line and nested ‘if’ statement without ‘?:’ (is it possible?)