やっぱりC++はやる価値ありまくりだな。

こんなコードを

#include <stdio.h>
int main() {
  int i = 0, j = 0;
  (1 ? i : j) = 300;
  printf("%d,%d\n", i, j);
}

gcc(cコンパイラ)とg++(c++コンパイラ)でコンパイルしてみよう!

~  % gcc test.c
test.c: In function ‘main’:
test.c:4: error: lvalue required as left operand of assignment
~  % g++ test.c
~  % ./a.out
300,0

おや? C++では ? 演算結果が左辺値なんですね。これは、なんというか、いいな!

test