“nil%2”的结果是什么?在 Objective-C 中?
Objective-c 中“nil%2”的答案是什么?我认为答案是 0 但我不确定。
谢谢。
What is the answer to "nil%2" in objective-c? I think the answer is 0 but I am not sure.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mod-2 运算不可能返回 2——只能返回 0 或 1。在这种情况下,我假设它是 0。
It's impossible for a mod-2 operation to return 2—only 0 or 1. I would assume, in this case, that it would be 0.
实际上答案是编译器错误。
nil
是一个指针(它被定义为(void *)0
),为指针定义的唯一算术运算是加法和减法。但如果你想知道 0%2 是什么,诺亚的答案是正确的。Actually the answer is a compiler error.
nil
is a pointer (it is defined as(void *)0
), and the only arithmetic operations defined for pointers are addition and subtraction. But if you wanted to know what 0%2 is Noah’s answer is right.