- 已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。
这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
9小时前关门了。
Improve this question
#include<stdio.h>
void swap(int *a , int *b){
int temp;
*a = temp;
*a = *b;
*b = temp;
}
int main()
{
int x,y;
printf("enter the first number : ");
scanf("%d" , &x);
printf("enter the second number : ");
scanf("%d" , &y);
printf("the value of x and y before swap are %d and %d and the address of x and y are %u and %u\n" , x , y , &x , &y);
swap(&x , &y);
printf("the value of x and y after swap are %d and %d and the address of x and y are %u and %u\n" , x , y , &x , &y);
return 0;
}
我尝试交换数字,当X值与Y值交换时,但Y值与X交换时,输出显示为-2。
1条答案
按热度按时间bttbmeg01#
temp
必须是*a
,而不是*a
必须是temp