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);
}
这到底是怎么一回事? 展开
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);
}
这到底是怎么一回事? 展开
3个回答
展开全部
不保存.cpp 编译的时候就用c++ 编译器
你用.c编译的时候用c编译器
还有就是c 不支持引用
你用.c编译的时候用c编译器
还有就是c 不支持引用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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里面这样写
#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里面这样写
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询