我是编程新手,目前正在研究C语言。
我了解到C没有通过引用调用。我们编写的将实际参数的地址传递给形参的程序在C中也是按值调用的。
如果我错了,请纠正我..然而,我运行了这个程序:
//使用函数交换两个数字#include
void swap(int *,int *);
void main()
{
int x,y;
printf ("Enter the values of x and y : ");
scanf("%d %d",&x,&y);
swap(x,y);
printf("The value of x = %d and y = %d",x,y);
}
void swap(int *a,int *b)
{
int temp;
temp=*b;
*b=*a;
*a=temp;
}它编译得很好..然而,我在输出中得到了一个分段错误。
它要求我输入X和Y的值,然后给出分割错误。
请帮帮我!!
https://stackoverflow.com/questions/44536143
复制相似问题