Function call

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Artikali
Learning poster
Posts: 68
Joined: Wed Sep 21, 2005 5:27 pm

Function call

Post 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
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post 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.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...
Post Reply

Return to “C++”