指针的一个简单应用

#include "stdafx.h"


int main(int argc, char* argv[])
{
//string s("hello world");
string s = "hello world";
string *p = &s;
*p = "goodbye";//此时字符串s的值也变化了
string *sp = &s;
sp = p;
*sp = "new another world";//都指向了同一内存地址
cout << s << endl;//s的值为new another world
return 0;
}

原文地址:https://www.cnblogs.com/xingmeng/p/2419464.html