If I have an array int a[10] (just for example) , I can pass the array to a function void myf ( int * x) with the call myf ( a ) . But with the 2-dimensional array int a[10][10] , using myf ( int ** x ) ( or ( int a[][]) with the call myf ( a ) will generate an error (unrelated pointed types , etc..) . Why ?
One and two - dimensional array passing
Collapse
X
-
Originally posted by VanKhaPlease help me . Thanks a lot.
its elements happen to be one dimensional arrays as well.
Similar to passing a one dimensional array 'a', where the parameter 'a' is considered
a pointer to its first element, as in:
[code=c]
char array[42]; // first element is a char
f(a);
...
void f(char* a) { ... }
[/code]
so is the two dimensional array considered a pointer to its first element:
[code=c]
char array[42][54]; // first element is a char[54]
f(a);
...
void f(char *a[54]) { ... }
[/code]
kind regards,
JosComment
-
Not correct:
Originally posted by JosAHchar array[42][54]; // first element is a char[54]
f(a);
...
void f(char *a[54]) { ... }
[code=cpp
char array[42][54]; // first element is a char[54]
f(a);
...
void f(char (*a)[54]) { ... }
[/code]Comment
Comment