C++/C编程学习:梳理08---C++中内置变量的初始化

原创:https://blog.csdn.net/luoweifu/article/details/39781399

如果内置类型的变量未被显示地初始化,它的值将由定义的位置决定。

(1).定义在函数体之外的变量将被初始化为0;

(2).定义在函数体内部的变量将不被初始化,它的值将是任意的。

实例:


short sn;
int in;
long ln;
long long lln;
float f;
double d;
long double ld;
bool b;
char c;
wchar_t wc;
int nArr[10];
 
void PrintVariable() 
{
	cout << "short:" << sn << endl;
	cout << "int:" << in << endl;
	cout << "long:" << ln << endl;
	cout << "long long:" << lln << endl;
	cout << "float:" << f << endl;
	cout << "double:" << d << endl;
	cout << "long double:" << ld << endl;
	cout << "bool:" << "he" << c << "llo" << endl;
	cout << "char:" << c << endl;
	cout << "wchar_t:" << "he" << wc << "llo" << endl;
	cout << "print array:" << endl;
	for (int i = 0; i < 10; i ++)
	{
		cout << nArr[i] << "    ";
	}
	cout << endl;

}
结果
short:0
int:0
long:0
long long:0
float:0
double:0
long double:0
bool:he llo
char: 
wchar_t:he0llo
print array:
0    0    0    0    0    0    0    0    0    0 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值