+ 1

Output of C++ code

Can someone explain the output of this code? #include <iostream> using namespace std; int main() { int a = 200, b = 100; int *p = &a, *q = &b; p = q; *p = 300; cout << b << a; return 0; } If I take out the line p=q; then it makes sense, but that line is really confusing me.

17th Aug 2021, 4:43 AM
Edward Finkelstein
Edward Finkelstein - avatar
2 Respostas
+ 5
p = q means p is now pointing to what q points to. You can think of it as p = &b;
17th Aug 2021, 4:59 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
CarrieForle Ah! That makes sense, thank you.
17th Aug 2021, 5:06 AM
Edward Finkelstein
Edward Finkelstein - avatar