结构体元素做函数参数:
结构体元素做参数 形参只能复制实参的值 并不能得到实参的地址 所以实参根本还没有任何变化
void copyTeacher(Teacher to,Teacher from)
{
to = from;
}
void main()
{
Teacher t1 = {"aaa",32,02};
Teacher t2;
memset(&t2,0,sizeof(t2));
copyTeacher(t1,t2);
printf("copyTeacher()after\n");
printf("t2.name:%s", t2.name);
printf("hehehe\n");
system("pause");
return;
}
结构指针做函数参数:
结构体指针做参数 传递的实参的地址
void copyTeacher02(Teacher* to, Teacher *from)
{
*to = *from;
}
void main()
{
Teacher t1 = {"aaa",32,02};
Teacher t2;
memset(&t2,0,sizeof(t2));
copyTeacher02(&t1,&t2);
printf("copyTeacher()after\n");
printf("t4.name:%s", t2.name);
printf("hehehe\n");
system("pause");
return;
}