C之交换数据案例
//值传递 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 }
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!