在C語言中,結(jié)構(gòu)體變量的賦值可以通過以下幾種方式實現(xiàn):
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));