二维数组问题 [英] Two dimensional array Question

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

问题描述

我仍然在第112页了解K& RII时遇到了问题。我已经查看了常见问题解答 - 我肯定会以某种方式回答它。

错过了,所以这里去了。

一个2-Dim数组,(每K& R)实际上是一个1-dim数组,每个元素都是

元素一个数组。

查看我使用的调试器,arr [2] [13]显示为初始值

的2,但扩展时,那里是连续2个阵列的13

元素。

所以,我可以问这个吗?

有什么特别的东西标志着第一个结束13个元素

从第二个13元素开始?换句话说,这似乎只是一个1-dim数组,其中包含有关声明提供的数组结构的信息



希望这是有道理的。


与此相关的练习,使用构造


* p = arr [1或0]指向第一或第一。或第二或第二

阵列。编译器是否知道在哪里指向,因为它已经通过13的声明给出了这个信息。在arr [2] [13]。

希望这也是有道理的!

最后,K& R'的描述每个元素都是一个数组

从来没有对我有意义。可能是上面的答案可以

澄清它。


提前谢谢。

I am still having a problem understanding K&RII on p 112. I have
looked at the FAQs --which I am sure answer it in a way that I have
missed, so here goes.
A 2-dim array, (per K&R) is really a 1-dim array, each of whose
elements is an array.
Looking at the debugger I use, arr[2][13] is shown as an initial value
of "2", but when expanded, there are 2 consecutive arrays of 13
elements.
So, may I ask this?
Is there anything special that marks the end of the first 13 elements
from the beginning of the 2nd 13 elements? In other words, it seems to
me that this is nothing more than a 1-dim array, with the information
about the structure of the array provided by the declaration?
Hopefully this makes sense.

The exercise associated with this, used the construct

*p = arr[1 or 0 ] to point to either the "first" or "second" row of
the array. Does the compiler "know" where to point to because it has
been given this information by the declaration of "13" in arr[2][13].
Hopefully this makes sense too!
And lastly, K&R''s description of "each of whose elements is an array"
has never made sense to me. It may be that the answer to the above may
clarify it.

Thanks in advance.

推荐答案

mdh写道:
mdh wrote:

我仍​​然在第112页理解K& RII时遇到问题。我有

查看常见问题解答 - 我肯定以一种我错过的方式回答它,所以这里有。

一个2-dim阵列,(每K& ; R)实际上是一个1-dim数组,每个元素都是一个数组。

查看我使用的调试器,arr [2] [13]是显示为初始值

的2,但展开时,有2个连续的13

元素数组。

所以,我可以问这个吗?

有没有什么特别的东西可以标出前13个元素的结尾

从第二个13元素的开头?换句话说,这似乎只是一个1-dim数组,其中包含有关声明提供的数组结构的信息



希望这很有意义。
I am still having a problem understanding K&RII on p 112. I have
looked at the FAQs --which I am sure answer it in a way that I have
missed, so here goes.
A 2-dim array, (per K&R) is really a 1-dim array, each of whose
elements is an array.
Looking at the debugger I use, arr[2][13] is shown as an initial value
of "2", but when expanded, there are 2 consecutive arrays of 13
elements.
So, may I ask this?
Is there anything special that marks the end of the first 13 elements
from the beginning of the 2nd 13 elements? In other words, it seems to
me that this is nothing more than a 1-dim array, with the information
about the structure of the array provided by the declaration?
Hopefully this makes sense.



完美感。以上都是正确的。鉴于''int arr [2] [13];'',arr是int的数组13的

数组2。连续26个整数。

Perfect sense. All above is correct. Given ''int arr[2][13];'', arr is an
array 2 of array 13 of int. 26 consecutive ints.


与此相关的练习,使用构造


* p = arr [1或0]指向第一或第一或第二或第二

阵列。编译器是否知道在哪里指向,因为它已经通过13的声明给出了这个信息。在arr [2] [13]。

希望这也是有道理的!
The exercise associated with this, used the construct

*p = arr[1 or 0 ] to point to either the "first" or "second" row of
the array. Does the compiler "know" where to point to because it has
been given this information by the declaration of "13" in arr[2][13].
Hopefully this makes sense too!



No. arr [0]是(地址)int的数组13。指针''p''必须声明
以反映这一点。


int(* p)[13];

现在p是一个指向int 13的数组13的指针。


p = arr [0];


.. 。说得通。

No. arr[0] is (the address of) an array 13 of int. The pointer ''p'' must
be declared to reflect this.

int (*p)[13];

Now p is a pointer to array 13 of int and..

p = arr[0];

...makes sense.


>

最后,K& R'描述每个元素都是一个数组

从来没有对我有意义。可能是上面的答案可能会澄清它。
>
And lastly, K&R''s description of "each of whose elements is an array"
has never made sense to me. It may be that the answer to the above may
clarify it.



我希望如此。你真的不太遥远。挂在那里。

I hope so. You''re really not too far off. Hang in there.


提前致谢。
Thanks in advance.



-

Joe Wright

所有东西都应尽可能简单,但不能简单。

---阿尔伯特爱因斯坦---

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---


Joe Wright写道:
Joe Wright wrote:

mdh写道:
mdh wrote:


完美感。以上都是正确的。鉴于''int arr [2] [13];'',arr是

int的数组13的数组2。连续26个整数。
Perfect sense. All above is correct. Given ''int arr[2][13];'', arr is
an array 2 of array 13 of int. 26 consecutive ints.

与此相关的练习,使用构造


* p = arr [1或0]指向第一或第一或第二或第二

阵列。编译器是否知道在哪里指向,因为它已经通过13的声明给出了这个信息。在

arr [2] [13]。希望这也是有道理的!
The exercise associated with this, used the construct

*p = arr[1 or 0 ] to point to either the "first" or "second" row of
the array. Does the compiler "know" where to point to because it has
been given this information by the declaration of "13" in
arr[2][13]. Hopefully this makes sense too!



编号arr [0]是int的数组13(的地址)。

No. arr[0] is (the address of) an array 13 of int.



不,它不是。它是int的数组13,而不是指向一个的数组。 arr是指向int 13数组的指针


No, it''s not. It is an array 13 of int, not a pointer to one. arr is a
pointer to array 13 of int.


指针''p''

必须声明反映这一点。


int(* p)[13];


现在p是一个指向int 13的数组13的指针..


p = arr [0];


..有意义。
The pointer ''p''
must be declared to reflect this.

int (*p)[13];

Now p is a pointer to array 13 of int and..

p = arr[0];

..makes sense.



不适合我。


p =& arr [0];


会。或OP有什么:


int * p;

p = arr [0];


Brian

Not to me.

p = &arr[0];

Would. Or what the OP had:

int *p;
p = arr[0];

Brian


mdh< md ** @ comcast.netwrites:


<讨论int a [2] [13];>
mdh <md**@comcast.netwrites:

<When discussing int a[2][13];>

最后,K& R'描述的每个元素都是一个数组

从来没有对我有意义。可能是上述答案可能会澄清它。
And lastly, K&R''s description of "each of whose elements is an array"
has never made sense to me. It may be that the answer to the above may
clarify it.



另一个想法......你有问题:


struct ints {int a,b,c, d,E,F,G,H,I,J,K,L,M; };

struct ints a [2];


是一个数组,每个元素的结构是13个整数?

如果我们说:


struct ints {int e [13]; };

struct ints a [2];


对于很多人来说,问题在于它的编写方式。如果它是

类似于:''int [13] a [2];''他们可能会发现更容易吞下

但数组声明符组如下:


int(a [2])[13];


(如果你愿意,你可以写出来!)所以a是一个2 ...数组的数组

13 ...整数。我认为你非常接近得到它。


-

Ben。

Another thought... Do you have a problem with:

struct ints { int a,b,c,d,e,f,g,h,i,j,k,l,m; };
struct ints a[2];

being an array, each of whose elements is a structure of 13 ints?
What if we say:

struct ints { int e[13]; };
struct ints a[2];

For many people the trouble is the way it is written. If it were
something like: ''int[13] a[2];'' they might find it easier to swallow
but the array declarators group like this:

int (a[2]) [13] ;

(you can write that if you want!) so a is "an array of 2... arrays of
13... ints. I think you are very close to "getting it".

--
Ben.


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

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