Skip to content

Instantly share code, notes, and snippets.

@myamamic
Created January 21, 2013 07:00
Show Gist options
  • Select an option

  • Save myamamic/4584110 to your computer and use it in GitHub Desktop.

Select an option

Save myamamic/4584110 to your computer and use it in GitHub Desktop.
[C/C++] 論理否定演算子の2重使い
C言語では、論理否定演算子(!)は「真か偽」ではなく、常に1か0を返すことが保証されているらしい。
なので、以下の文は意味がある。
int value, x, y;
int a = !!value;
int b = !!(x & y);
→aとbは、1か0になる。
# でも、3項演算子と同義らしい。
int a = value? 1 : 0;
int b = (x & y)? 1 : 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment