#include using namespace std; int main() { string food = "Pizza"; // A food variable of type string cout << "Output value and address by variable and reference" << endl; cout << food << endl; // Outputs the value of food (Pizza) cout << &food << endl; // Outputs the memory address of food (0x6dfed4) // 定义指针 cout << "Output value and address by pointer" << endl; string* ptr = &food; cout << *ptr << endl; cout << ptr << endl; // 修改指针指向内存的值 cout << "Modify value by pointer" << endl; *ptr = "Hamburger"; // 指针指向变量的值也被改变了 cout << food << endl; }