C++學習_一道程序填空題重拾C++

題目描述

填空,使得程序輸出指定結果

輸入:python

輸出:ios

123,456  

程序以下:數組

#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;
}

RRRspa

目前還沒學會!!!指針


 2019年7月23日18:00 終於搞定了!0.0blog

完整代碼

#include <iostream>
using namespace std;

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

輸入參數解析

// 輸入參數以下
0,new int,new int,new int, new int
// 解析
// 由於int * a[] 表示定義一個數組,數組元素所有都是整型指針
// 而 new int 恰好返回int * 類型 
// 並且保證 !a[0]爲真才能正確輸出 *a[2]和a[3][5]的內容 

RRRio

相關文章
相關標籤/搜索