char中的char初始值 [英] char initial value in Java

查看:167
本文介绍了char中的char初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

初始化方法中定义的 int 变量,使其值为 0 ,直到计算出特定值为 int 。什么可以将 char 的值初始化为?

char retChar =''; 这给出了错误,如果我初始化为 -1 ,则表示字符过多。

You initialize an int variable defined within a method to have a value of 0 until you compute specific values for the int. What can one initialize char values to?
char retChar = '';this gives an error and if I initialise to -1 it says too many characters.

推荐答案

通常,对于本地变量,我会尽可能地初始化它们。我很少需要虚拟值。但是,如果您执行,您可以使用您喜欢的任何值 - 如果您确定在阅读之前要分配值,则不会有任何区别。

Typically for local variables I initialize them as late as I can. It's rare that I need a "dummy" value. However, if you do, you can use any value you like - it won't make any difference, if you're sure you're going to assign a value before reading it.

如果你想要 char 相当于0,它只是Unicode 0,可以写成

If you want the char equivalent of 0, it's just Unicode 0, which can be written as

char c = '\0';

这也是实例(或静态)变量的默认值输入 char

That's also the default value for an instance (or static) variable of type char.

这篇关于char中的char初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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