I have this question and answer as provided below:
int m = 5; int n = m; int *p1 = &m; int *p2 = &n; m = 10; p2 = p1; *p2 = 7; The question asks what are the value of all the following and the answers are:
m=7, n=5, *p1=7, *p2=7
This is what I tried:
m is an int of value 5. n is an int whose value is assigned to the value of m, which is 5 and p1 and p2 and initialised to be pointers to m and n.
Then I change the value of m to be 10, so m is 10 and n is 5
Then when I set p2 = p1, both pointers point to m
When I change the variable pointed to by p2 to be 7, n becomes 7, so m = 10, n = 7 and p1 and p2 points to n which has a value of 7.
Therefore:
m=10, n=5, *p1=7, *p2=7
what am I doing wrong here?
EDIT: SOLVED