C++, multidimensional array -


when multidimensional array passed function, why c++ require first dimension specified in parameter li

a better way ask ask why c++ doesn't require first dimension specified.

the reason all arrays, can't pass arrays value function. if try declare function taking array compiler adjust declaration corresponding pointer type.

this means doesn't matter dimension specify dimension doesn't form part of function signature.

for example, these declare same function.

void f(int *p); void f(int p[]); void f(int p[10]); void f(int p[100]); 

when navigating array pointed p in function, information copmiler needs size of array elements, i.e. sizeof(int) in case.

for more complex arrays same holds. these same:

void g(type p[][10][20]); void g(type (*p)[10][20]); void g(type p[10][10][20]); void g(type p[99][10][20]); 

but these different from:

void g(type p[][5][20]); 

because adjusting dimension of other outer array dimension affects size of (at least) outer array's elements meaning pointer arithmetic navigating array have change.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -