&之间的差异(&)和&&或| (管道)和||在Objective-C中?
问题描述:
我想知道Objective-C是否关心我是否撰写&或&& ;?我相信一个&号会导致或应该导致,如果LEFT一侧已经为假,则不会对右侧进行评估.
I wonder if Objective-C does care about whether I write & or &&? I believe one ampersand (&) would or should cause that if the LEFT side is already false, then the right side won't be evaluated.
这是否适用于Objective-C?
Does this apply to Objective-C?
答
是.运算符在C和Objective-C中的功能相同.
Yes. The operators function identically in C and Objective-C.
就像在C(或C ++,如果您使用的是Objective-C ++)中一样,&
和|
是按位的,而&&
和||
是逻辑(和短路)的.按位运算符(&
和|
)不是短路.
Just like in C (or C++, if you're using Objective-C++) &
and |
are bit-wise and &&
and ||
are logical (and short-circuit). Bit-wise operators (&
and |
) are not short-circuit.
请参见使用C和C ++的操作符