c++ - 二维数组初始化问题
PHPz
PHPz 2017-04-17 15:04:38
0
3
574


d选项为什么是正确的,答案是c,AB选项可以理解

PHPz
PHPz

学习是最好的投资!

reply all(3)
刘奇

Just one thing to say: The data is initialized row by row. I don’t need to know how many rows there are, but I must know how many data are in a row (that is, how many columns). This is two-dimensional, and then expand In 3 dimensions, I don’t need to know how many pages of data there are, but I must know how many rows and columns a page of data stores.

---Gorgeous dividing line---

If it is greater than or equal to two dimensions, the first one can be omitted. The others cannot be omitted. The first one is not necessarily the number of rows. It is just a metaphor, so it is easier to understand and remember.

就像你有一些 麻将, 按行来排列. 你只需要知道一行放几个(几列), 就可以知道放几行. (2维) 
int arr[行数][5];
如果知道了行和列, 你就能推算出放几层了. (3维) 
int arr[层数][5][5];
如果知道了行,列,层, 我就能知道放几堆了. (4维)
int arr[堆数][5][5][5];
如果知道了行,列,层,堆, 我就能推算出可以放在几张桌子上了.(5维)
int arr[桌子数][5][5][5][5];
如果知道了行,列,层,堆,桌子的张数, 我就能推算出, 我要用几间屋子来存放了.(6维)
int arr[屋子][5][5][5][5][5];
...

数字化之后:
int arr[n-1]...[6][5][4][3][2][1][0]; 

n-1下标是可以省略的.其他都不可以;

Mastering methods and learning analogies is more important than anything else; don’t memorize answers.

巴扎黑

You should know why option C is wrong, right? I’ll just talk about option D. In C language, initializing multi-dimensional arrays in these two ways is equivalent,

int a[3][4] = {  
   {0, 1, 2, 3} ,   
   {4, 5, 6, 7} ,   
   {8, 9, 10, 11}   
};

and

int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};

For initialization of multi-dimensional arrays, we don’t need so many curly braces at all. On page 162 of "C and Pointers", the author points out that curly braces are used just for easy identification, as shown in the picture above.

大家讲道理

When declaring and assigning a two-dimensional array, the length of the second dimension must be specified, and the first dimension can be omitted

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!