Created
January 21, 2013 07:00
-
-
Save myamamic/4584110 to your computer and use it in GitHub Desktop.
[C/C++] 論理否定演算子の2重使い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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