Does an int in Objective-C have a default value of 1?

前端 未结 4 1304
刺人心
刺人心 2020-12-19 13:29

I have this simple line of code:

int x;

x automatically has the value of 1. I don\'t set it to anything but when I debug, it s

4条回答
  •  执笔经年
    2020-12-19 13:45

    No. int has an undefined default value. It just happens to be 1 in this case. It could just as easily be -18382 or 22 or 0xBAADF00D.

    Always initialize your variables in C.

提交回复
热议问题