私は一般的にポインタのロジックのアイデアを思いつきましたが、基礎となるコードの一部に関連する不明確な点があります。
#include <iostream>
using namespace std;
int main ()
{
int first = 50,
second = 150;
int * p1, * p2;
p1 = &first; //p1 is assigned to the address of first
p2 = &second; //p2 is assigned to the address of second
*p1 = 100; //first's value is changed as 100 by assigning p1's value to 100
*p2 = *p1; //now p2's value should be 100
p1 = p2; //I think we want to change p1's adress as p2
*p1 = 200; //I expect that the new value of p1 should be 200
cout << first << second;
return 0;
}
プログラムはfirst=100とsecond=200を出力しますが、上でコメントしたように、p1の値は200に変更されると思います。しかし、それでも100のままです。そのポイントは何ですか。