Hidden Features of C++?


Question

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++?

1
114
9/9/2009 11:44:49 PM

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 :-)

308
1/7/2009 9:59:34 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon