c - Two dimensional array address and corresponding pointer to its 1st element -
in terms of 1 dimensional array, array name address of first element. fine assign pointer, below:
char data[5]; char* p_data=data; so think should same 2 dimensional array. array name should address of first element's address. so, i'd this:
char data[5][5]; char** pp_data=data; then warning saying pointer type char** incompatible char[ ][ ].
why happen? comprehend pointer , array concept wrong?
you're right array referred pointer first element. when have "two dimensional" array
char data[5][5]; what have array of arrays. first element of array data array of 5 characters. code work:
char (*pa_data)[5] = data; here pa_data pointer array. compiler won't complain it, may or may not useful you.
it's true pointer-to-pointer char **pp_data can made act two-dimensional array, have memory allocation work. turns out in array-of-arrays char data[5][5] there's no pointer-to-char pp_data pointer to. (in particular, not pp_data = &data[0][0].)
see this question in c faq list.
Comments
Post a Comment