在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));