1

Using no other objects besides those already declared, how can you alter ptrptr so that it points at a pointer to b without directly touching ptr ?

int a,b;
int *ptr;
int**ptrptr;

ptr =&a;
ptrptr=&ptr;
2
  • What does this have to do with array, vector or resize? Please reduce your tags to just those that describe the problem you are having. Commented Nov 1, 2016 at 17:29
  • ops .. sry mate ,i was about to ask something but i have figured it on my own so i deleted it and forgot to remove the tages .. thnx Commented Nov 1, 2016 at 18:02

1 Answer 1

2

You're not allowed to touch directly ptr. So ptr = &b; is not an option.

But this doesn't prevent changing it indirectly. So *ptrptr=&b; would be the way to go.

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

4 Comments

That is not actually altering (changing) ptrptr. It is changing *ptrptr so it points to b (i.e. contains the address of b), which is a somewhat different from the question asked.
I think it is the exact answer to this question. How to work with pointers to pointer?
i got the question from a book called Data structure and problem solving by mark Allen .. isnt changing the address normally changes the value assigned to it ?
@ahmedelbarky Suppose a=1; and b=2;. None of these pointer statements change the value contained in a or in b. It only changes the pointers themselves. If you print **ptrptr immediately after your code, you'd get 1. If you print **ptrptr after my statement, you'd get 2. But a and b are still unchanged. If after my statement you'd assign **ptrptr=3; then only the content of b would be changed to 3.

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.