c++ - Confused with pointer and double pointer in the heap -
i'm getting confused pointers , double pointers.
suppose have these
int* ptr = new int[2]; here, ptr has address of array of size 2 in heap keeps int data right?
int** ptr = new int* [2]; here, ptr has address 2 pointers in heap , these 2 pointers can point int data.
is thinking here correct?
this correct: in first case assign pointer memory block in heap sufficient storing 2 ints, can considered int array of size two.
the second ptr assigned pointer memory block in heap sufficient storing 2 pointers int. however, these pointers not point in particular until assign them value*, in same way assign other pointers. example, can make second ptr make array of 2 int arrays, this:
int** ptr = new int* [2]; ptr[0] = new int[2]; ptr[1] = new int[2]; * same true ints first code snippet: value indeterminate until assign them.
Comments
Post a Comment