C语言到底支不支持引用传递做函数参数?

同样一段代码,保存为cpp文件,在VC6.0下顺利运行,但是保存为c文件,连编译都不能通过。显示如下诸多错误:errorC2143:syntaxerror:missing... 同样一段代码,保存为cpp文件,在VC6.0下顺利运行,但是保存为c文件,连编译都不能通过。显示如下诸多错误:
error C2143: syntax error : missing ')' before '&'
error C2143: syntax error : missing '{' before '&'
......
代码如下:
#include<stdio.h>
typedef struct { int x, y,width,height; } Rect;
void Exchg3(Rect &x, Rect &y)
{
int tmp = x.height;
x.height = y.height;
y.height = tmp;
printf("x.height = %d,y.height = %d\n", x.height, y.height);
}
main()
{
Rect a = {1,2,3,4};
Rect b = {5,6,7,8};
Exchg3(a, b);
// printf("a = %d, b = %d\n", a, b);
return(0);
}
这到底是怎么一回事?
展开
 我来答
百度网友a5eb3e1
推荐于2017-10-06 · TA获得超过4447个赞
知道大有可为答主
回答量:3486
采纳率:60%
帮助的人:2606万
展开全部

“引用传递做函数参数”是C++的特性,C语言不支持。



// C语言要这样写:
void Exchg3(Rect *x, Rect *y){ /* ... */ }

// 然后传递指针:
Exchg3(&a, &b);
IT孤鹜
2014-05-25 · TA获得超过4196个赞
知道大有可为答主
回答量:3960
采纳率:71%
帮助的人:3487万
展开全部
不保存.cpp 编译的时候就用c++ 编译器
你用.c编译的时候用c编译器

还有就是c 不支持引用
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
吾屺情彩包29
2014-05-25 · TA获得超过272个赞
知道小有建树答主
回答量:182
采纳率:0%
帮助的人:137万
展开全部
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct { int x, y, width, height; } Rect;
void Exchg3(Rect x, Rect y)
{
int tmp = x.height;
x.height = y.height;
y.height = tmp;
printf("x.height = %d,y.height = %d\n", x.height, y.height);
}
int main()
{
Rect a = { 1, 2, 3, 4 };
Rect b = { 5, 6, 7, 8 };
Exchg3(a, b);
printf("a = %d, b = %d\n", a, b);
return(0);
}
C里面这样写
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式