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是否关心我是否写&或&&?我相信一个与号(&)将会或应该导致如果LEFT侧已经为假,那么右侧将不会被评估。
Does this apply to Objective-C?
这适用于Objective-C吗?
2 个解决方案
#1
22
Yes. The operators function identically in C and Objective-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 ++,如果你使用的是Objective-C ++)和&是按位和&&和||是逻辑的(和短路)。逐位运算符(&和|)不是短路的。
请参阅C和C ++中的运算符
#2
3
Objective-C uses the C bitwise and logical operators (& is bitwise and && is logical). The single & will evaluate both expressions.
Objective-C使用C位按位和逻辑运算符(&是按位,&&是逻辑)。单曲&将评估两个表达式。
#1
22
Yes. The operators function identically in C and Objective-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 ++,如果你使用的是Objective-C ++)和&是按位和&&和||是逻辑的(和短路)。逐位运算符(&和|)不是短路的。
请参阅C和C ++中的运算符
#2
3
Objective-C uses the C bitwise and logical operators (& is bitwise and && is logical). The single & will evaluate both expressions.
Objective-C使用C位按位和逻辑运算符(&是按位,&&是逻辑)。单曲&将评估两个表达式。