介绍一下“指针交换”的原理
void main()
{
char *a[]={"k","t"};
swap(a);
for(int i=0;i<2;i++)
printf("%s ",a[i]);
}*
[解决办法]
- C/C++ code
void swap1(int x,int y)//函数内部交换了参数,对main中的啊a,b没有影响{ int temp; temp=x; x=y; y=temp;}void swap2(int &a,int &b)//引用类型交换参数相当于交换了,被引用的变量a,b对main中a,b有影响{ int temp; temp=a; a=b; b=temp;}void swap3(int *a,int *b)//交换指针指向的值,对main中a,b有影响{ int temp; temp=*a; *a=*b; *b=temp;}void swap4(int *a,int *b)//交换的是指针而不是指针指向的值(参考swap1解释),对main中a,b无影响{ int* temp; temp=a; a=b; b=temp;}