我是编程的新手,我目前正在研究C.
我了解到C没有通过引用调用.我们编写的用于将实际参数的地址传递给形式参数的程序也由C中的值调用.
如果我错了,请纠正我.但是,我运行了这个程序:
//使用函数交换两个数字.#包括
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;
}
Run Code Online (Sandbox Code Playgroud)
它编译得很好..但是,我在输出中遇到了分段错误.
它要求我输入X和Y的值然后给出,分段错误..
请帮忙!!