
在函数中引用链表作为参数为什么不行
#include<stdio.h>#include<conio.h>typedefstructlinklist{charc;structlinklist*next;}*l...
#include<stdio.h>
#include<conio.h>
typedef struct linklist
{
char c;
struct linklist *next;
}*lnode,*linklist;
void print( linklist l)
{
lnode temp1;
temp1=l;
lnode temp2;
while( temp1->c != '#' )
{
printf("%c->",temp1->c);
temp1=temp1->next;
}
getch();
}
void changel(linklist L) //这样没错 如果改成 void print( linklist &L ) 就错了
{
L=L->next;
}
int main()
{
linklist l;
l=(lnode)malloc(sizeof(lnode));
lnode temp1;
temp1=l;
lnode temp2;
while(1)
{
char ch;
ch = getchar();
temp1->c = ch;
if(ch == '#' )break;
temp2 = (lnode)malloc(sizeof(lnode));
temp1->next =temp2;
temp1 = temp2;
}
print(l);
printf("\n");
changel(l);
print(l);
} 展开
#include<conio.h>
typedef struct linklist
{
char c;
struct linklist *next;
}*lnode,*linklist;
void print( linklist l)
{
lnode temp1;
temp1=l;
lnode temp2;
while( temp1->c != '#' )
{
printf("%c->",temp1->c);
temp1=temp1->next;
}
getch();
}
void changel(linklist L) //这样没错 如果改成 void print( linklist &L ) 就错了
{
L=L->next;
}
int main()
{
linklist l;
l=(lnode)malloc(sizeof(lnode));
lnode temp1;
temp1=l;
lnode temp2;
while(1)
{
char ch;
ch = getchar();
temp1->c = ch;
if(ch == '#' )break;
temp2 = (lnode)malloc(sizeof(lnode));
temp1->next =temp2;
temp1 = temp2;
}
print(l);
printf("\n");
changel(l);
print(l);
} 展开
2个回答
展开全部
void print( linklist &L )
你这样是什么意思呢,如果你想传地址过去的话,函数定义的时候也应该是void print( linklist *L ),只有在函数调用的时候才用 print( &L ) 这种形式。
再说linklist本身就是指针类型的了,所以,不需要加*,这个函数还可以这样写
void print( struct linklist *L ),调用的时候还是一样
楼上的方法纯属扯淡
你这样是什么意思呢,如果你想传地址过去的话,函数定义的时候也应该是void print( linklist *L ),只有在函数调用的时候才用 print( &L ) 这种形式。
再说linklist本身就是指针类型的了,所以,不需要加*,这个函数还可以这样写
void print( struct linklist *L ),调用的时候还是一样
楼上的方法纯属扯淡
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询