定义整型(INT);什么是默认值? [英] Define integer (int); What's the default value?

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

问题描述

  INT I;
int数据[5] = {0};
数据[0] = I;

什么是数据值[0]

此外,什么是此行的意义?

 如果(!数据[0]){...}


解决方案

在大多数情况下,有一个 INT 对象没有默认值。

如果您声明 INT I; 作为函数内部的(非静态)局部变量,它有一个不确定的值。它是未初始化的,直到你写一个有效的值给它,你不能使用它。

这是一个好习惯进入显式初始化的任何对象,当你把它声明。

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

What's the value in data[0]?

Also, what's the meaning of this line?

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

解决方案

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

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天全站免登陆