EXPLORATION 46

image

More Operators

C++ has lots of operators. Lots and lots. So far, I’ve introduced the basic operators that you require for most programs: arithmetic, comparison, assignment, subscript, and function call. Now it’s time to introduce some more: additional assignment operators, the conditional operator (which is like having an if statement in the middle of an expression), and the comma operator (most often used in for loops).

Conditional Operator

The conditional operator is a unique entry in the C++ operator bestiary, being a ternary operator, that is, an operator that takes three operands.

condition ? true-part : false-part

The condition ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.