#include <iostream>
using namespace std;
/*
如果对左操作数进行解引用,则修改的是指针所指对象的值
如果没有进行解引用则修改的是指针本身的值
*/
int main(int argc, char const *argv[])
{
string s1("hello");
string *sp1 = &s1;
cout <<s1 <<endl;
cout<<*sp1<<endl;
cout<<"----------"<<endl;
*sp1 = "world";
cout <<s1 <<endl;
cout<<*sp1<<endl;
string s2("C++");
string *sp2 = &s2;
sp1 = sp2;
cout<<"----------"<<endl;
cout <<s1 <<endl;
cout<<*sp1<<endl;
system("pause");
return 0;
}
C++ 指针1
最新推荐文章于 2022-08-03 18:32:28 发布