In Objective-C, are int variables that haven't been assigned a value nil?

前端 未结 4 766
-上瘾入骨i
-上瘾入骨i 2021-01-22 12:09

If I have this in my .h file:

int index;

And then in the .m file I have:

if (index == nil)

4条回答
  •  别那么骄傲
    2021-01-22 12:54

    The value of an integer that hasn't yet been assigned depends on its declaration - an int with static storage duration is zero if you don't assign it anything else. An int with automatic or allocated storage duration could have any value if you don't explicitly initialize it.

    By the way, putting an object declaration in your header like that is bound to cause you pain later.

提交回复
热议问题