Page 1 of 1

Function call

Posted: Mon Oct 30, 2006 5:11 am
by Artikali
How can i built function which have multidimension array.
here is my code

Code: Select all

#include <iostream>
#include <cstdio>
using namespace std;
#define N 100
int put(int ** a){
	a[0][0]=1;
	return 0;
}
int main(){
	int c[N][N];
	put(c);
	cout<<c[0][0]<<endl;
	return 0;
}
it gave me compile error.
thanks

Posted: Mon Oct 30, 2006 5:24 am
by Krzysztof Duleba

Code: Select all

int put(int a[][100]) {
  // ...
}
In order to evaluate expressions like a[x][y], the compiler has to do something like *(a + x * 100 + y). Note that it must know all dimensions of the array, perhaps except for the first one. However, if you just pass is a pointer (int **), the compiler will have no clue about that.

You can also use vectors (of vectors), they work as expected.