asd6791868 发布留言 2008-7-28 21:34
问个关于指针的问题~
#include
#include
void swap(int **p1, int **p2)
{
int *temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
int main()
{
int a, b;
int *pointer_1, *pointer_2;
scanf("%d%d", &a,&b);
pointer_1 = &a;
pointer_2 = &b;
if (a < b)
swap(&pointer_1,&pointer_2);
printf("%d %d\n",*pointer_1,*pointer_2);
printf("%d %d\n",a,b);
system("PAUSE");
return 0;
}
=======================================================================int *temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
给上面的东西加个注释。搞不懂啊*p1是引用的什么?
temp = *p1; 一级指针为什么指向了二级指针?
int *temp; int temp;
temp = *p1; temp=**p1;
*p1 = *p2; 和 **p1=**p2;
*p2 = temp; **p2=temp;
有什么区别???
=======================================================================高手帮帮我啊~有些乱啊!!!!!!!!谢谢各位!
=======================================================================yejingx 发布留言 2008-7-28 22:34
void swap(int **p1, int **p2)
{
int *temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
temp = *p1 //**p1是二级指针,*p1是一组指针(二级指针的值),temp也是一级指针
上面函数的作用就是交换两个指针的值(地址),而不是 实际的内存数据.
页: [1]