Hi C++ quick question.

int x, y, *p = &x, *q = &y;
x = 35 ;
y = 46;
*p = 78;
cout << x << " " << y << endl;
cout << *p << " " << *q << endl;

the solution is 35 78
78 78

i wonder why "y" is 78 , if so why "x" is not affected?
i am confused with the * and & <----

explain please.
thanks
Your code:

1
2
3
4
5
6
int x, y, *p = &x, *q = &y;
x = 35 ;
y = 46;
*p = 78;
cout << x << " " << y << endl;
cout << *p << " " << *q << endl;


I can't see the output being anything other than
78 46
78 46
yes
the output would be
78 46
78 46

i wonder why "y" is 78 , if so why "x" is not affected?

you do not change the "y"
x is changed, print out again to see..
Topic archived. No new replies allowed.