注册 登录
编程论坛 C++教室

帮忙翻译一下!

tymstill 发布于 2008-04-14 14:56, 723 次点击
To write a function that has a two-dimensional array as an argument, you need to remember that the name of an array is treated as its address, so the corresponding formal parameter is a pointer, just as for one-dimensional arrays. The tricky part is declaring the pointer correctly. Suppose, for example, we start with this code:

int data[3][4] = { {1,2,3,4}, {9,8,7,6}, {2,4,6 8}};
int total = sum(data, 3);

What should the prototype for sum() look like? And why does the function pass the number of rows (3) as an argument and not also the number of columns (4)?
则sum()的原型是什么样的呢?函数为何将行数(3)作为参数,而将列数(4)作为参数呢?

感觉这个红色的部分翻译不对啊?
2 回复
#2
jackie_wyx2008-04-14 15:25
我觉得应该是:“而不将列数(4)作为参数呢?”
#3
toidy2008-04-14 15:43
献丑了:
编写一个一二维数组为参数的函数,记住,数组的名字被看作是它的地址,所以相应的参数应该是一个指针,就像一位数组一样。该函数的技巧就是要正确地声明指针。比如,下面的代码:

那么,sun()的原型是什么样的呢?为什么函数只传递了三行这一参数,而不同时传递四列这一参数呢?
1