#include <iostream>
using namespace Std;
int value=1;
void func (int *p)
{
p=&value;
}
void func (int **p) .... Overload
{
*p=&value;
}
int main ()
{
int a=3;
int *ptr;
ptr=&a;
cout<<*ptr<<endl;
Func (PTR), ...... It's a copy.
cout<<*ptr<<endl;
Func (&PTR);
cout<<*ptr<<endl;
return 0;
}
、、、、、、、、、、、、、、、、、、
void Fun3(int *&p)
{
p=&value;
}
。。。。。。。。。。。。。
Fun3 (PTR);
cout<<*ptr<<endl;
The result is 1, and the argument is a reference to the pointer , not a copy but an address
int & *p is wrong
Reproduced:
Li Peng Source: http://www.cnblogs.com/li-peng/The author and the blog Park share, Welcome to reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
#include <iostream>
using namespace Std;
void Fun4 (int *a)
{
*a=9;
cout<<*a<<endl;
}
int main ()
{
int a=3;
Fun4 (&a);
cout<<a<<endl;
return 0;
It's not a copy.
Pointer C 艹