包含内置类型的类的默认赋值操作符,会对每一个成员逐一赋值。如下。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct UNIT
{
int total;
int used;
char name[10];
};
int main()
{
UNIT test, asign;
test.total = 100;
test.used = 40;
strcpy(test.name, "lanmao");
asign = test;
printf("-----UNIT.total:%d--------\r\n", asign.total);
printf("-----UNIT.used:%d--------\r\n", asign.used);
printf("-----UNIT.name:%s--------\r\n", asign.name);
return 0;
}
结果如下: