An interesting feature of C++ is that the result of the ?: operator is an lvalue (a value that can be assigned to) if the second and third operands are both lvalues. This means for example that an expression with the ?: operator can appear on the left side of an assignment operator.

For example, (e==5?a:b) = 10; is almost equivalent to:

if (e == 5)
  a = 10;
else
  b = 10;

The difference is that the first statement is an expression that has a value (10), but the second isn't an expression.

Below is a little program that shows some of the possibilities. I have tested it with Borland C++ 5.5 for Win32 and gcc/g++ version 2.95.2.

#include <iostream.h>

int main(void)
{
  int a=1, b=2, c=3, d=4, e=5, *f=&a;
  (e==5?a:b) = 10;
  (e==7?c:d) = 11;
  cout << "a: " << a << " b: " << b << " c: " << c << " d: " << d << endl;
  e = (e==9?a:b) = 12;
  cout << "a: " << a << " b: " << b << " c: " << c << " d: " << d;
  cout << " e: " << e << endl;
  (e==b?(e==3?*f:b):c) ++;
  cout << "a: " << a << " b: " << b << " c: " << c << " d: " << d << endl;
  f = &((e==b?(e==3?*f:b):c));
}
/* Expected output:
a: 10 b: 2 c: 3 d: 11
a: 10 b: 12 c: 3 d: 11 e: 12
a: 10 b: 13 c: 3 d: 11
*/


A little remark, thanks to m_turner: It is possible to achieve a similar effect in C by writing *(e==5?&a:&b) = 10;. Here we use the ?: operator to choose between the addresses of the variables. Then we apply the dereference operator (*) to the expression, which produces an lvalue that can be assigned to.