Question

What is the answer to "nil%2" in objective-c? I think the answer is 0 but I am not sure.

Thank you.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top