2

Quick questions about pointers. In this example:

  Object *O;

  Object** array = new Object*[3];

  O = array[0];

In this example, Does O point to the spot array[0] or the object located in the position? For example, if that object in index 0 gets swapped to say object in spot 2, I understand that O should still have access to that object not the new one now in array[0], right?

Sorry just want to double check. Been working over a day w/o sleep & starting to question what's what at this point.

Fox
  • 595
  • 1
  • 4
  • 10
  • http://stackoverflow.com/questions/5727/what-are-the-barriers-to-understanding-pointers-and-what-can-be-done-to-overcome?rq=1 –  May 10 '13 at 07:15

1 Answers1

1

Your assumptions are correct.

When doing the O = array[0]; assignment (which is equivalent to writing O = (*array);) you copy the pointer stored in the array to your pointer variable O. Any change to the array afterwards won't change the contents of O, since it is a copy.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166