指针的一个简单应用

#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;
}

posted @ 2012-03-27 13:56  幻星宇  阅读(138)  评论(0编辑  收藏  举报