结构体的值传递和地址传递
代码为:
#include<stdio.h>
#include<string.h>
struct Student
{
int age;
char name[50];
int score;
};
void chstrStu1(struct Student st1)
{
st1.age = 20;
strcpy(st1.name,"lisi");
st1.score = 100;
printf("chtrStu1 age = %d name = %s score = %d\n",st1.age,st1.name,st1.score);
}
void chstrStu2(struct Student *st1)
{
st1->age = 20;
strcpy(st1->name,"lisi");
st1->score = 100;
printf("chtrStu2 age = %d name = %s score = %d\n",st1->age,st1->name,st1->score);
}
int main()
{
struct Student s1 = {18,"zhangsan",60};
printf("使用值传递\n");
printf("before age = %d name = %s score = %d\n",s1.age,s1.name,s1.score);
chstrStu1(s1);
printf("after age = %d name = %s score = %d\n",s1.age,s1.name,s1.score);
printf("使用地址