在C語言中,結構體可以通過以下幾種方式進行賦值:
struct Person {
char name[20];
int age;
};
struct Person p;
strcpy(p.name, "Alice");
p.age = 25;
struct Person p = {"Bob", 30};
struct Person p1 = {"Alice", 25};
struct Person p2;
memcpy(&p2, &p1, sizeof(struct Person));
struct Person p1 = {"Alice", 25};
struct Person p2;
struct Person *ptr1 = &p1;
struct Person *ptr2 = &p2;
*ptr2 = *ptr1;