C++でポインタ変数と参照変数を学習していますが、私が見たサンプルコードがあります。私はなぜ* cの値が33から22に変わったのか分かりません。誤解だ新しい値を割り当てなかったときに変数の値が変更されるのはなぜですか?
int a = 22;
int b = 33;
int* c = &a; //c is an int pointer pointing to the address of the variable 'a'
int& d = b; //d is a reference variable referring to the value of b, which is 33.
c = &b; //c, which is an int pointer and stored the address of 'a' now is assigned address of 'b'
std::cout << "*c=" << *c << ", d=" << d << std::endl; //*c= 33 d= 33
d = a; //d is a reference variable, so it cannot be reassigned ?
std::cout << "*c=" << *c << ", d=" << d << std::endl; //*c= 33 d= 33
ありがとうございます! – Skipher
@Skipher、よろしいですか? –