8

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?

Proud Member
  • 39,470
  • 44
  • 145
  • 229

2 Answers2

23

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.

See Operators in C and C++

3

Objective-C uses the C bitwise and logical operators (& is bitwise and && is logical). The single & will evaluate both expressions.

Kevin Sylvestre
  • 36,131
  • 31
  • 148
  • 228