P
Paul
If you really must know how to use it without crashing here is one way:Leigh Johnston said:No they are related types. Related because:Leigh Johnston said:On 23/03/2011 16:27, Paul wrote:
[...]
int (*p3)[dim] = &arr; /*Pointless extra level of indirection [see
note]*/
int** p4 = &arr; /*Same as above, but without typeinfo*/
Untrue; int (*p3)[dim] is not the same as int** (they are totally
unrelated types).
int (*p3)[dim]; /*-- points to an array of int.---*/
int** p4; /* ---- points to an int* ---- */
The followings shows they both point to the same place:
int arr[5]={1,2,3,4,5};
int (*p)[5] = &arr;
int** pp = (int**)&arr;
std::cout<< "value of p:\t"<<p <<"\nvalue of pp:\t" <<pp;
I just forgot the cast.
Using the result of that cast is UB:
std::cout<< **pp;
int* temp = (int*)*p; /* --Convert p to int* first--*/
int** pp = &temp; /* ---Assign address of p to pp---*/
So what it was an example to explain the extra level of indirection. Ifwill probably cause a crash.
wasn't meant to be compileable code.
I have now shown you how to do it with compileable code and the same context
still applies.