定义整数(int);默认值是多少? [英] Define integer (int); What's the default value?

查看:17
本文介绍了定义整数(int);默认值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int i;
int data[5] = {0};
data[0] = i;

data[0] 中的值是多少?

What's the value in data[0]?

另外,这行是什么意思?

Also, what's the meaning of this line?

if (!data[0]) { ... }

推荐答案

在大多数情况下,int 对象没有默认"值.

In most cases, there is no "default" value for an int object.

如果您将 int i; 声明为函数内部的(非静态)局部变量,则它具有不确定的值.它是未初始化的,在你写入一个有效值之前你不能使用它.

If you declare int i; as a (non-static) local variable inside of a function, it has an indeterminate value. It is uninitialized and you can't use it until you write a valid value to it.

在声明对象时明确初始化任何对象是一个好习惯.

It's a good habit to get into to explicitly initialize any object when you declare it.

这篇关于定义整数(int);默认值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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