C代码错误,火速选最佳答案

来源:百度知道 编辑:UC知道 时间:2024/05/21 10:00:36
#include<STDIO.H>
void swap(int x,int y);
void main()
{
int a,b;
a=5; b=10;
printf("befor swap:a=%d,b=%d\n",a,b);
swap(a,b);
printf("after swap:a=%d,b=%d\n",a,b);
}
void swap(int x,int y);
{
int temp;
printf("in swap,first:x=%d.y=%d\n",a,b);
temp=x; x=y; y=temp;
printf("in swap,last:x=%d,y=%d\n",x,y);
}
编译器说
void swap(int x,int y);
{
这里错了?

void swap(int x,int y); /*多了个分号*/
{
int temp;
printf("in swap,first:x=%d.y=%d\n",a,b);
temp=x; x=y; y=temp;
printf("in swap,last:x=%d,y=%d\n",x,y);
}

函数调用语句的后面可以有分号,
而函数定义语句的后面不可以有分号.