int main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
int *p,*q;
int j;
p=&a[0];
q=&a[0];
for(int i=0;i<7;i++)
{
srand(time(0));
j=1+rand()%9;
cout<<"j= "<<j<<endl;
cout<<"first *p ="<<*p<<endl;
cout<<"first *q ="<<*q<<endl;
p=&a[j];
cout<<"after *p ="<<*p<<endl;
cout<<"after *q ="<<*q<<endl;
if(q==p)
cout<<"OVER!"<<endl;
}
return 0;
}
如果if中是 p=q ,结果会这样呢?在first那里是一样的!