1 # include <stdio.h> 2 3 /* 定义一个全局的结构体 */ 4 struct student 5 { 6 long num; 7 char name[20]; 8 char sex; 9 int age; 10 }; 11 12 /* 声明结构体数组并赋初值 */ 13 struct student stu[4] = {{97032, "xiao ming", 'M', 20}, 14 {97033, "xiao wang", 'M', 20}, 15 {97034, "xiao tong", 'M', 21}, 16 {97035, "xiao shui", 'F', 18}}; 17 18 void main() 19 { 20 /* 定义一个结构体指针变量 */ 21 struct student *p; 22 23 printf(" 学号 姓名 性别 年龄 "); 24 for(p=stu; p<stu+4; p++) 25 printf("%-8ld%-12s%-10c%-3d ", p->num, p->name, 26 p->sex, p->age); 27 }