&之间的差异(&)和&&或| (管道)和||在Objective-C中? [英] Difference between & (ampersand) and && or | (pipe) and || in Objective-C?

查看:87
本文介绍了&之间的差异(&)和&&或| (管道)和||在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 ++的操作符

这篇关于&之间的差异(&)和&&或| (管道)和||在Objective-C中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆