Proud Member
Proud Member

Reputation: 40496

Difference between & (ampersand) and && or | (pipe) and || in Objective-C?

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

Answers (2)

user166390
user166390

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.

See Operators in C and C++

Upvotes: 24

Kevin Sylvestre
Kevin Sylvestre

Reputation: 38032

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

Upvotes: 4

Related Questions