数组指针问题 [英] array pointer question
问题描述
让我们说我有一个2D数组,我怎么用指针访问它?
int x [2] [2];
func(x);
void func(int * x){
//我想用数字填充它,比如1
}
let''s say i have a 2D array, how would i access it with a pointer?
int x [2][2];
func(x);
void func(int *x) {
//i want to fill it with a number, like 1
}
推荐答案
Dmitrii PapaGeorgio写道:
Dmitrii PapaGeorgio wrote:
let'假设我有一个2D数组,我怎么用指针访问它?
int x [2] [2];
func(x);
void func(int * x){
//我想用一个数字填充它,比如1
}
let''s say i have a 2D array, how would i access it with a pointer?
int x [2][2];
func(x);
void func(int *x) {
//i want to fill it with a number, like 1
}
忘了......数组被传递为func(x [0])
forgot...the array is being passed as func(x[0])
Dmitrii PapaGeorgio写道:
Dmitrii PapaGeorgio wrote:
让我们说我有一个2D数组,我怎么用指针访问它?
int x [2] [2];
func(x);
void func(int * x){
//我想用一个数字填充它,比如1
}
let''s say i have a 2D array, how would i access it with a pointer?
int x [2][2];
func(x);
void func(int *x) {
//i want to fill it with a number, like 1
}
上面的arr ay看起来像这样:
+ --- + --- + --- + --- +
| 0,0 | 0,1 | 1,0 | 1,1 |
+ --- + --- + --- + --- +
每个方框代表一个整数。索引是n,m为:x [n] [m]。
-
WW aka Attila
The above array looks like this:
+---+---+---+---+
|0,0|0,1|1,0|1,1|
+---+---+---+---+
Each box represent an integer. The indices are n,m as: x[n][m].
--
WW aka Attila
<当我尝试分配一个值时,函数内部的
我得到一个错误说
它不是指针或数组,如
x [1] [2] = 1;
WW写道:
inside the function when i try to assign a value i get an error saying
it''s not a pointer or array like
x[1][2] = 1;
WW wrote:
Dmitrii PapaGeorgio写道:
Dmitrii PapaGeorgio wrote:
let我说我有一个2D数组,我怎么用指针访问它?
int x [2] [2];
func(x);
void func(int * x){
//我想用一个数字填充它,比如1
}
let''s say i have a 2D array, how would i access it with a pointer?
int x [2][2];
func(x);
void func(int *x) {
//i want to fill it with a number, like 1
}
上面的数组如下:
+ --- + --- + --- + --- +
| 0,0 | 0,1 | 1,0 | 1, 1 |
+ --- + --- + --- + --- +
每个方框代表一个整数。索引为n,m为:x [n] [m]。
The above array looks like this:
+---+---+---+---+
|0,0|0,1|1,0|1,1|
+---+---+---+---+
Each box represent an integer. The indices are n,m as: x[n][m].
这篇关于数组指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!