I am confused about pointers and double pointers.
Understand that we have
int * ptr = new int [2];
Here, the PTR has two array of shapes in the heap which keeps the int data correct?
int ** ptr = new int * [2];
Here, PTR has two points addressed in a heap and these two points can point to some int data.
Is my thinking right here?
This is almost right: in the first case you have enough blocks to block two, one in the memory block Specify the pointer int
s, which can be considered as an array of size code .
However, these pointers do not specifically point to anything, unless you assign them some value, just like you assign to other pointers. For example, you can create second ptr
to create two int
arrays, such as:
int ** ptr = new Int * [2]; PTR [0] = new int [2]; PTR [1] = new int [2]; It is correct with your first code snippet for
s: their value is uncertain unless you specify them do.
No comments:
Post a Comment