c++ 编程练习 004:神秘的数组初始化

描述

填空,使得程序输出指定结果

#include <iostream>
using namespace std;

int main()
{
	int * a[] = {
// 在此处补充你的代码
};
	
	*a[2] = 123;
	a[3][5] = 456;
	if(! a[0] ) {
		cout << * a[2] << "," << a[3][5];
	}
	return 0;
}

输入

输出
123,456

样例输入

样例输出
123,456

来源
Guo Wei


分析

就是建立一个指针数组,每一个数组元素都指向一个地址,利用new动态建立即可。

#include<iostream>
using namespace std;

int main()
{
	int* a[] = { NULL,new int[5],new int[5],new int[5] };
	*a[2] = 123;
	a[3][5] = 456;
	if (!a[0]) {
		cout << *a[2] << "," << a[3][5];
	}
	return 0;
}

在这里插入图片描述

发布了196 篇原创文章 · 获赞 47 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_44116998/article/details/104354993