1 #include
2 Exchg3(int &x, int &y)
3 {
4 int tmp=x;
5 x=y;
6 y=tmp;
7 printf("x=%d,y=%d\n",x,y);
8 }
9 int main()
10 {
11 int a=4;
12 int b=6;
13
14
15 Exchg3(a,b);
16 printf("a=%d,b=%d\n", a, b);
17 }
ab.c:2: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
考乌特莫克 于 2011-02-19 22:17:35发表:
用g++编译器就可以过了
child7 于 2010-09-08 19:52:12发表:
另外,main函数没有返回 return 0;
zzm35837995 于 2010-09-07 12:58:59发表:
:0)1谢谢各位,老师也是这样讲的
sauntor 于 2010-09-06 22:33:08发表:
楼上说的对,在C语言里没有C++所谓的“按引用传递”,即Exchg3(int &x, int &y)应改为Exchg3(int *x, int *y)然后再这样调用Exchg3(&a, &b)就不会出错了,当然前提是你得把Exchg3(int *x, int *y)修改正确了(o):tx
shenhao0129 于 2010-09-06 20:25:36发表:
函数参数传递的有问题
dfwclm 于 2010-09-06 16:32:46发表:
不懂,帮顶