Objective-C中的int是否具有默认值1? [英] Does an int in Objective-C have a default value of 1?

查看:121
本文介绍了Objective-C中的int是否具有默认值1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这么简单的代码:

int x;

x 自动获得值1。我没有设置它,但是当我调试时,它显示 x 是1.

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

是否 int 的默认值是1?!

推荐答案

否。 int 具有未定义的默认值。在这种情况下,它恰好是 1 。它可以很容易地 -18382 22 0xBAADF00D

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.

始终在C中初始化变量。

Always initialize your variables in C.

这篇关于Objective-C中的int是否具有默认值1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆