【发布时间】:2021-11-02 17:23:10
【问题描述】:
由于指针部分的一些运行时错误,我的代码运行异常。 这是我的代码,因为我犯了错误而表现得很奇怪。
#include<stdio.h>
void swap(int*, int*);
int main()
{
int a, b;
printf("Enter the value of a : ");
scanf("%d",&a);
printf("Enter the value of b : ");
scanf("%d",&b);
swap(&a,&b);
printf("Values of a and b after swapping are %d and %d respectively\n",a,b);
}
void swap(int *a, int *b)
{
int *temp;
printf("asdf");
*temp=*a;
printf("asdf");
*a=*b;
*b=*temp;
}
输出是 输入 a 的值:5 输入 b 的值:2 asdf 我错误地将 temp 设为指针变量而不是简单的整数变量。但是为什么我的代码不能继续工作并最终出现在那里?
【问题讨论】: