小问题求解
#include<iostream.h>
struct stud
{
int no;
char name[10];
struct stud *next;
};
void fun(struct stud *s)
{
s=s->next;
}
void main()
{
int i;
struct stud s[2]={{1,"mary"},{2,"smith"}};
struct stud *h;
s[0].next=&s[1];
s[1].next=&s[0];
h=&s[0];
fun(h);
for (i=0;i<2;i++)
{
cout << h->name << ":" << h->no << " ";
h=h->next;
}
cout << endl;
}
按我的理解h引用了s[0],接着调用了void fun(struct stud *s),应该是s[0]变为了s[1]嘛,但是输出结果没变,这个是为什么啊,谁能给讲讲
[解决办法]
问题在这个函数调用上,因为你传递了一个临时拷贝,所以没有改变。