+ 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.
2 Respostas
+ 5
p = q means p is now pointing to what q points to.
You can think of it as p = &b;
+ 2
CarrieForle Ah! That makes sense, thank you.