C语言结构体数组的初始化赋值可以通过以下两种方式进行:
struct Student {
char name[20];
int age;
};
int main() {
struct Student students[3];
strcpy(students[0].name, "Tom");
students[0].age = 18;
strcpy(students[1].name, "Alice");
students[1].age = 20;
strcpy(students[2].name, "Bob");
students[2].age = 19;
return 0;
}
struct Student {
char name[20];
int age;
};
int main() {
struct Student students[3] = {
{"Tom", 18},
{"Alice", 20},
{"Bob", 19}
};
return 0;
}
通过上述两种方式,可以对C语言中的结构体数组进行初始化赋值。