Take the 2-minute tour ×

When you create the multi-dimenstional array char a[10][10], according to my book it says you must use a parameter similar to char a[][10] to pass the array to a function.

Why must you specify the length as such? Aren't you just passing a double pointer to being with, and doesn't that double pointer already point to allocated memory? So why couldn't the parameter be char **a? Are you reallocating any new memory by supplying the second 10.

share|improve this question

2 Answers 2

up vote 11 down vote accepted

Pointers are not arrays

A dereferenced char ** is an object of type char *.

A dereferenced char (*)[10] is an object of type char [10].

Arrays are not pointers

See the c-faq entry about this very subject.

Assume you have

char **pp;
char (*pa)[10];

and, for the sake of argument, both point to the same place: 0x420000.

pp == 0x420000; /* true */
(pp + 1) == 0x420000 + sizeof(char*); /* true */

pa == 0x420000; /* true */
(pa + 1) == 0x420000 + sizeof(char[10]); /* true */

(pp + 1) != (pa + 1) /* true (very very likely true) */

and this is why the argument cannot be of type char**. Also char** and char (*)[10] are not compatible types, so the types of arguments (the decayed array) must match the parameters (the type in the function prototype)

share|improve this answer
The explanation you gave is very clear, thank you :-). –  rubixibuc Apr 5 '11 at 21:23
Also that link you provided is awesome. –  rubixibuc Apr 5 '11 at 21:31
You're welcome. Glad you like the c-faq. Don't read just section 6: read all of it. –  pmg Apr 5 '11 at 21:32

C language standard, draft n1256: Lvalues, arrays, and function designators

Given a declaration of

char a[10][10];

the type of the array expression a is "10-element array of 10-element array of char". Per the rule above, that gets coverted to type "pointer to 10-element array of char", or char (*)[10].

Remember that in the context of a function parameter declaration, T a[N] and T a[] are identical to T *a; thus, T a[][10] is identical to T (*a)[10].

share|improve this answer
Thank you for posting that, it helped me too. :-) –  rubixibuc Apr 5 '11 at 21:24

Your Answer


