What does this do int **baken
I’ve never understood this double **. Is it a pointer to a second pointer that points forward to a third variable.
[edited by - leadorn on January 19, 2003 1:51:42 PM]
So it automatically goes forward when reaching a double pointer. Can I user triple....?
Cant get it to work, can you give me an example please?
Cant get it to work, can you give me an example please?
You can use them to dynamically allocate 2d arrays
int **myl33tArray;myl33tArray = new int*[ARRAY_WIDTH];for (int i = 0; i < ARRAY_WIDTH; i++) myl33tArray = new int[ARRAY_HEIGHT];<br> </pre> <br><br>Access it like: myl33tArray[2][4] = 100;<br><br><SPAN CLASS=editedby>[edited by - glassJAw on January 19, 2003 2:26:57 PM]</SPAN>
I have one more q!
if i use your 2d array, is this the correct way to deallocate the array?
if i use your 2d array, is this the correct way to deallocate the array?
allocint **Map;Map = new int*[ARRAY_WIDTH];for (int i = 0; i < ARRAY_WIDTH; i++) Map[ i ] = new int[ARRAY_HEIGHT];dealloc for (unsigned int i = 0; i < ARRAY_WIDTH; i++) { delete [] Map[i]; } delete [] Map;
One more use for pointers to pointers is in linked lists.
Normally you would have the following to add a member to a link-list...
Or you could have the following, which removes the special case for the head of list...
PS: Yes you can have triple pointers, or for that matter quad-pointers, or an depth of pointers to pointers.
[edited by - Beelzebub on January 31, 2003 5:44:32 PM]
Normally you would have the following to add a member to a link-list...
if (pFirst == NULL) pFirst = pNew;else{ STRUCT *p; p = pFirst; while (p->pNext != NULL) p = p->pNext; p->pNext = pNew;}pNew->pNext = NULL;
Or you could have the following, which removes the special case for the head of list...
STRUCT **ppNext;ppNext = &pFirstwhile (*ppNext != NULL) ppNext = &((*ppNext)->pNext);*pNext = pNew;pNew->pNext = NULL;
PS: Yes you can have triple pointers, or for that matter quad-pointers, or an depth of pointers to pointers.
[edited by - Beelzebub on January 31, 2003 5:44:32 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement