c程序指针题

题目一:

#include<stdio.h>
void temp(int x,int y){

 int temp;
 temp = x;
 x = y;
 y = tmp;
 
 printf("temp函数打印:x=%d,y=%d
",x,y);
}

void main(void){

 int a = 10 , b = 20;
 tmpx(a,b);
 printf("main函数打印:a=%d,b=%d
",a,b);

}

 输出结果:

 x = 20 , b = 10;

   a = 10 , b = 20;

题目二:

#include<stdio.h>
void temp(int *x,int *y){
 
 int temp = *x;
 *x = *y;
 *y = temp;
 
 printf("temp函数打印:*x=%d,*y=%d
",*x,*y);

}
void main(void){

 int a = 10,b = 20;
 temp(&a,&b);
 printf("main函数打印:a=%d,b=%d
",a,b);

}

 输出结果:

 *x = 20 , *b = 10;

   a = 20 , b = 10;

 题目三:

#include<stdio.h>
void temp(int &x,int &y){

 int temp = x;
 x = y;
 y = temp;
 printf("temp函数打印:x=%d,y=%d
",x,y);
}

void main(void){

 int a = 10,b = 20;
 temp(a,b);
 printf("main函数打印:a=%d,b=%d
",a,b);

}

 输出结果:

 x = 20 , b = 10;

   a = 20 , b = 10;

 

原文地址:https://www.cnblogs.com/NigelX/p/6548468.html