这段代码为什么不能实现我所想的效果?
#include <iostream>
using namespace std;
void funcTest1(int&,int*);
void funcTest2(int&,int*);
int main()
{
int endLine;
int first,second;
int *pntSecond=&second;
cout<<"Please input two number:";
cin>>first>>second;
cout<<"first="<<first<<",second="<<second<<endl;
funcTest1(first,pntSecond);
cout<<"first="<<first<<",second="<<second<<",*pntSecond="<<*pntSecond<<endl;
funcTest2(first,pntSecond);
cout<<"first="<<first<<",second="<<second<<",*pntSecond="<<*pntSecond<<endl;
cin>>endLine;
return 0;
}
void funcTest1(int &first,int *second)
{
first=99;
*second=999;
}
void funcTest2(int &first,int *second)
{
second=&first;
}
为什么funcTest2()执行后,*pntSecond依然指向999,而不是first的99呢?
我的运行环境:mac+xcode