hi guys I am c++ user and i have question about changing pointer
exsample
1 2 3 4 5
int x = 1;
int y = 2;
int*z = &x;
int*w = z;
now i want to change z pointer to from x to y using w assuming i dont have z.
so if i said
w = &y; that mean i cahnged w itself or
*w = y; i changed w,z's value
can you help me guys? thanke you :)
I think I know what you are asking. If 'w' was a pointer to a pointer int ** w; then yes you can do this. As you have it written now though it won't work.
In your code w is not pointing to z. w is pointing to x. If you want w to be able to point to z you will have to change the type to int** (pointer to pointer to int).
1 2 3 4 5 6
int x = 1;
int y = 2;
int* z = &x;
int** w = &z;
*w = &y; // z will now point to y