<求助>用指针变量输出结构数组
程序代码:
#include<stdio.h> struct stu { int num; char *name; //为什么是*name而不是name? char sex; float score; }boy[5]={ {101,"Zhou ping",'M',45}, {102,"Zhang ping",'M',62.5}, {103,"Liou fang",'F',92.5}, {104,"Cheng ling",'F',87}, {105,"Wang ming",'M',58}, }; void main() { struct stu *ps; printf("No\tName\t\t\tSex\tScore\t\n"); for(ps=boy;ps<boy+5;ps++) printf("%d\t%s\t\t%c\t%f\t\n",ps->num,ps->name,ps->sex,ps->score); }为什么换成
程序代码:
#include<stdio.h> struct stu { int num; char name; char sex; float score; }boy[5]={ {101,'Z','M',45}, {102,'Z','M',62.5}, {103,'L','F',92.5}, {104,'C','F',87}, {105,'W','M',58}, }; void main() { struct stu *ps; printf("No\tName\t\t\tSex\tScore\t\n"); for(ps=boy;ps<boy+5;ps++) printf("%d\t%s\t\t%c\t%f\t\n",ps->num,ps->name,ps->sex,ps->score); }就会出错.