编写程序定义一个结构体数据类型并说明一个结构体数据类型的数组,通过指针变量输出该数组中各元素的值
时间: 2023-05-27 19:08:01 浏览: 97
#include <stdio.h>
struct student {
int id;
char name[20];
int score;
};
int main() {
struct student stu_array[3] = {
{1, "Tom", 80},
{2, "Jerry", 90},
{3, "Alice", 85}
};
struct student *p = stu_array;
int i;
for(i=0; i<3; i++) {
printf("id: %d, name: %s, score: %d\n", (p+i)->id, (p+i)->name, (p+i)->score);
}
return 0;
}
阅读全文