That is not right. Pointer-to-pointer is totally a different thing from a 2-D array or a pointer to a 2-D array. Try casting a pointer to a 2D array to a pointer-to-pointer. You CAN'T. Even in the case of 1D, you may cast a pointer to a 1D array to a pointer, it is still worth pointing out that pointer and 1D array are DIFFERENT things. Any one failing to see that should fail a job interview.Quote:
Pointer-to-pointer has multiple interpretations (2D-array for example), so it's not always obvious that it means that a value may be returned.
a[0] may or may not be valid depending how a is declared. If a is an array, then it is valid. If a is a pointer, a[0] may not be valid.
A pointer-to-pointer has only ONE possible interpretation:
Step1.Use this pointer-to-pointer, suppose it point to a valid address (The pointer-to-pointer is neither NULL nor point to invalid address), you may fetch (or store back) a pointer.
Step2.Use the pointer fetched in step1, suppose it is a valid pointer, (The pointer value is neither NULL nor point to invalid address) You can fetch (or store back) a value of the type. If there is a const modifier before the pointer-to-pointer declaration (const int ** mypp;), then you can noly fetch but not store back.
Nothing in the pointer-to-pointer implies any thing that may be an array. Actually to access elements in a 2D array you follow different steps:
1.take the x and y index of the element and use them to calculate an index. (index = y*X_DIMENTION + x)
2.Use the index to and treat the 2D array like 1-D array to fetch the value.
For example:
is actually implemented something like this 1D array:Code:int a[16][16];
int b = a[1][2];
Code:int a[16 * 16];
int b = a[1*16 + 2];
