C++ 수정 포인터
포인터 값 수정
포인터의 값을 변경할 수도 있습니다. 그러나 이렇게 하면 원래 변수의 값도 변경됩니다.
예시
string food = "Pizza";
string* ptr = &food;
// Output the value
of food (Pizza)
cout << food << "\n";
// Output the memory address
of food (0x6dfed4)
cout << &food << "\n";
// Access the memory
address of food and output its value (Pizza)
cout << *ptr << "\n";
// Change the value of the pointer
*ptr = "Hamburger";
//
Output the new value of the pointer (Hamburger)
cout << *ptr << "\n";
//
Output the new value of the food variable (Hamburger)
cout << food << "\n";