Hi I am Joon who is studying C++ with this website.
I have question about one of part. At the part 'Declaring pointers' the example
// more pointers
#include <iostream>
using namespace std;
int main ()
{
int firstvalue = 5, secondvalue = 15;
int * p1, * p2;
p1 = &firstvalue; // p1 = address of firstvalue
p2 = &secondvalue; // p2 = address of secondvalue
*p1 = 10; // value pointed to by p1 = 10
*p2 = *p1; // value pointed to by p2 = value pointed by p1
p1 = p2; // p1 = p2 (value of pointer is copied)
*p1=20; // value pointed by p1 = 20
If you're wondering why firstvalue stayed at the value of 10, it's because the pointer p1 was changed to point to the address of secondvalue. Then when you did *p1 = 20, it actually set the secondvalue to 20, but not firstvalue since p1 was no longer pointing toward it.
Edit:
p1 = p2; // p1 = p2 (value of pointer is copied)
The code above is where the p1 was changed to point toward the secondvalue instead of firstvalue