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.

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.