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