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

前端 未结 4 763
-上瘾入骨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:37

    The variable is technically undefined (may have any value) before you assign it a value. Most likely, it will be equal to zero. Also, both nil and NULL are defined to zero. However, this comparison is not recommended. You should only use nil when comparing pointers (it is not intended to be used with primitives).

提交回复
热议问题