Description
指针的功能多种多样,指针是c语言的灵魂,所以说掌握指针是很重要的。
下面要求你用指针实现两个数字的交换
Input
两个int型的变量
Output
交换后的两个变量
Sample Input
1 2
Sample Output
2 1#include<iostream> using namespace std; int main() { int a,b; int *c=&a,*d=&b; void exc(int*,int*); cin>>a>>b; exc(c,d); cout<<a<<" "<<b<<endl; return 0; } void exc(int *c1,int *d1) { int p; p=*c1; *c1=*d1; *d1=p; }