//值传递 void swap(int i,int j){ printf("交换后:\n "); int tmp; tmp = i; i = j; j = tmp; } //引用传递,传递地址 void swap1(int* p,int* q){ printf("交换后:\n "); int tmp; tmp = *p; *p = *q; *q = tmp; } main(){ int i =3; int j = 5; printf("i=%d \n",i); //i = 3 printf("j=%d \n",j); //j = 5 //交换数值 swap1(&i,&j); printf("i=%d \n",i); //i = 5 printf("j=%d \n",j); //i = 3 }
时间: 2024-10-07 20:02:14