#include "stdio.h"
void main( )
{
struct {
char initial;
int age;
int grade;
} kids[12], *point, extra;
我正在按照这里的教程http://www.gatesit.org/gitdownloads/C&DS.pdf第 813-22 页,我不太明白什么孩子[12],*点,额外;方法。据我所知,您可以在定义它之后初始化结构的变量,但为什么会有一个大小为 12 的数组、一个指针等等?
这是它后面的代码。
int index;
for (index = 0; index < 12; index++)
{
point = kids + index;
point->initial = 'A' + index;
point->age = 16;
point->grade = 84;
}
kids[3].age = kids[5].age = 17;
kids[2].grade = kids[6].grade = 92;
kids[4].grade = 57;
for (index = 0; index < 12; index++)
{
point = kids + index;
printf("%c is %d years old and got a grade of %d\n",
(*point).initial, kids[index].age, point->grade);
}
extra = kids[2]; /* Structure assignment */
extra = *point; /* Structure assignment */
}