Hidden Features of C++?

Craig H picture Craig H · Sep 16, 2008 · Viewed 80.7k times · Source

No C++ love when it comes to the "hidden features of" line of questions? Figured I would throw it out there. What are some of the hidden features of C++?

Answer

Ferruccio picture Ferruccio · Nov 19, 2008

Most C++ programmers are familiar with the ternary operator:

x = (y < 0) ? 10 : 20;

However, they don't realize that it can be used as an lvalue:

(a == 0 ? a : b) = 1;

which is shorthand for

if (a == 0)
    a = 1;
else
    b = 1;

Use with caution :-)