在C语言中,结构体变量的赋值可以通过以下几种方式实现:
struct Person {
char name[20];
int age;
};
struct Person p1;
p1.age = 25;
strcpy(p1.name, "Alice");
struct Person {
char name[20];
int age;
};
struct Person p1 = {"Alice", 25};
struct Person p2 = p1;
struct Person {
char name[20];
int age;
};
struct Person p1 = {"Alice", 25};
struct Person p2;
memcpy(&p2, &p1, sizeof(struct Person));