用C多维数组初始化 [英] Multidimensional array initialization in C

查看:108
本文介绍了用C多维数组初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Kochen读的书,编程的C,我很困惑,他解释多维数组的此处。特别是,我不明白下面这句话的意思注意的是,在这种情况下,括号内对被要求强制正确的初始化。如果没有他们,前两行和第三行的前两个元素会被替代初始化。我不知道到底这句话是什么意思。

I am reading the book, "Programming in C" by Kochen and I am confused where he explains the initialization of multidimensional array here. In particular, I don't understand the meaning of the following sentence Note that, in this case, the inner pairs of braces are required to force the correct initialization. Without them, the first two rows and the first two elements of the 3rd row would have been initialized instead. I'm not sure what the heck the sentence means.

推荐答案

通过内部括号中的数组是这样的:

With the inner braces the array looks like this:

10  5 -3  0  0
 9  0  0  0  0
32 20  1  0  0
 0  0  8  0  0

因此​​,在每行的最后2的值是零(因为你没有为他们设定一个值。
如果没有内部括号中的数组是这样的:

So in every line the last 2 values are zero (because you didn't set a value for them. Without the inner braces the array would look like this:

10  5 -3  9  0
 0 32 20  1  0
 0  8  0  0  0
 0  0  0  0  0

只有前12个元素将成为给定的值,其余为0。

Only the first 12 elements would become the given values and the rest will be 0.

这篇关于用C多维数组初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆