首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小疑点求解

2012-02-15 
小问题求解#includeiostream.hstruct stud{int nochar name[10]struct stud *next}void fun(struct

小问题求解
#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]嘛,但是输出结果没变,这个是为什么啊,谁能给讲讲

[解决办法]
问题在这个函数调用上,因为你传递了一个临时拷贝,所以没有改变。

热点排行