结构体赋值方法
结构体数组赋值的赋值方法
typedef struct { short Id; char Sstr[19]; } TestStr; 第一种:
TestStr ls_TestStr[] = {{0,"hello0"},{1,"hello11"}}; 第二种: TestStr ls_TestStr[2]; TestStr[0].Id = 0; TestStr[0].Sstr[19] = "hello"; TestStr[1].Id = 1; TestStr[1].Sstr[19] = "helloll"; 第三种: TestStr ls_TestStr[2] = {{0,"hello0"},};//此时只是对结构体数组ls_TestStr[0]进行了赋值
错误示例:
TestStr ls_TestStr[2] = {0,"hello0"};//这种赋值是错误的,并不能将所有的结构体数组都赋值