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;
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;
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.
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.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.