关于数据结构中的“&”问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:31:03
正在学数据结构(C语言版),书上说增添了C++的“&”。
void InitList(SqList &sq)
{
sq.length=0;
}
这条程序中“&”在TUBRO C2.0中调试不了提示是Declaration syntax error。
但在Microsoft Visual Studio 2008中调试的了。
是不是“&”只能在C++中用?若是,用什么替换。
还是写的程序错了?
#include<stdio.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef char ElemType;
typedef struct
{
ElemType data[LIST_INIT_SIZE];
int length;
} SqList;
void InitList(SqList &sq)
{
sq.length=0;
}
int GetLength(SqList sq)
{
return sq.length;
}
int GetElem(SqList sq,int i,ElemType &e)
{
if(i<1||i>sq.length)
return 0;
else
{
e=sq.data[i-1];
return 1;
}
}
int Locate(SqList sq,ElemType x)
{
int i=0;
while(sq.data[i]!=x)
i++;
if(i>sq.length)
return(0);
else
return(i+1);
}
int InsElem(

“&”在C++中如果放在声明变量前面,表示这个变量为一个“引用”。如果这个“引用”被作为函数的参数,那么形参的值变了,实参的值也会变。所以如果要换成C语言的形式需要用指针代替。