专业编程基础技术教程

网站首页 > 基础教程 正文

c++ 数组用{}初始化 c++中数组初始化

ccvgpt 2024-10-10 05:02:41 基础教程 11 ℃

int arr[10] = {};

实际上数组里的内容已经是这样子:0000000000

c++ 数组用{}初始化 c++中数组初始化

总结:数组如果像这样使用初始化列表初始化将为你提供默认值,否则未初始化的将是乱值。

int main()
{
	int table[][2] = { {1} , {} };
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			cout << table[i][j] << endl;
		}
	}
	getchar();
	return 0;
}

程序输出结果:

1 0

0 0


最近发表
标签列表