在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;
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: c语言闰年判断代码怎么写