pointer to a pointer

Started by
10 comments, last by kag1 19 years, 10 months ago
Yes, arrays are sequential, including 2d arrays as you mentioned.
//Sequentialint array[3][3];//Not necessarily sequentialint ** ppInt = new int * [3];ppInt[0] = new int[5];     ppInt[1] = new int[2];ppInt[2] = new int[15]; 


There are 3 different int arrays being allocated in the second part, and they could be anywhere. Note that they are not even the same length. It is not even square conceptually, like a 2d array is.

Edit: forgot a semicolon


[edited by - KrazeIke on June 4, 2004 10:39:15 PM]
Advertisement
Yes. ** Means a poiner to a pointer. So when you use

int ** array;

as a multi-demensional array like:

int ** array = new array*[2];array[0] = new int[3];     array[1] = new int[10]; 


At first you are creating an array of pointers to int pointers. Then you are setting the pointers to the address of an array you are allocating. That''s why it''s not necessarily be sequential.

This topic is closed to new replies.

Advertisement