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

前端 未结 4 1308
刺人心
刺人心 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 14:06

    The initial value is undefined, and in this case will be whatever happened to be in that memory location before x started using it.

    (Depending on the surrounding code, you might find that in your specific case it's always 1, but you can't be sure of that.)

提交回复
热议问题