谁帮我解释一下..结构体的问题
#include "stdio.h"#include "conio.h"
struct s
{
int a;
char b;
};
struct s* bi(struct s d)
{
struct s *p1;
d.a=100;
d.b='a';
p1=&d;
return &d;
}
int main()
{
struct s *p;
struct s sk;
sk.a=155,sk.b='z';
printf("%d,%c\n",sk.a,sk.b);
p=bi(sk);
printf("%d,%c\n",p->a,p->b);//这个结果为什么 100 a
getch();
return 0;
}
===============================================
#include "stdio.h"
#include "conio.h"
struct s
{
int a;
char b;
};
struct s* bi(struct s d)
{
struct s *p1;
d.a=100;
d.b='a';
p1=&d;
return p1;
}
int main()
{
struct s *p;
struct s sk;
sk.a=155,sk.b='z';
p=bi(sk);
printf("%d,%c\n",sk.a,sk.b);
printf("%d,%c\n",p->a,p->b); //这个为什么是155 z呢.p不是接受bi函数的地址吗?
getch();
return 0;
}
[[it] 本帖最后由 bianfeng 于 2008-4-20 15:14 编辑 [/it]]