&和&&
最近在看《The C Programming Language 2nd Ed》,把其中自己認(rèn)為值得注意的地方記下來。小弟水平有限,若哪個(gè)地方理解錯(cuò)了還請(qǐng)各位GGJJ指出。先謝謝了。
<<TCPL 2ED>>
P46 倒數(shù)第二段 (2.9 Bitwise Operators)
One must distinguish the bitwise operators & and | from the logical operators && and ||, which imply left-to-right evaluation of a truth value. For example, if x is 1 and y is 2, then x & y is zero while x && y is one.
---------
1 & 2 就是 01 & 10 -> 00
1 && 2 就是 true && true -> true
無論什么語言都要注意位操作符和邏輯與或的區(qū)別。
用程序驗(yàn)證一下,gcc 3.4.2,^_^











輸出結(jié)果:
x=1, y=2
x & y : 0 : FALSE
x && y : 1 : TRUE
posted on 2007-12-14 12:53 yanvenhom 閱讀(526) 評(píng)論(0) 編輯 收藏 引用 所屬分類: C/C++