Reputation: 40496
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.
Does this apply to Objective-C?
Upvotes: 8
Views: 10478
Reputation:
Yes. The operators function identically in C and 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.
Upvotes: 24
Reputation: 38032
Objective-C uses the C bitwise and logical operators (& is bitwise and && is logical). The single & will evaluate both expressions.
Upvotes: 4