结构体指针

include <stdio.h>

struct stu
{
int num;
char *name;
char sex;
float score;
} boy1 = {102, "Fishc", 'M', 78.5};

void main()
{
struct stu *pstu;
pstu = &boy1;

  printf("Number = %d\nName = %s\n", boy1.num, boy1.name);      
  printf("Sex = %c\nScore = %f\n\n", boy1.sex, boy1.score);      

  printf("Number = %d\nName = %s\n", (*pstu).num, (*pstu).name);      
  printf("Sex = %c\nScore = %f\n\n", (*pstu).sex, (*pstu).score);      

  printf("Number = %d\nName = %s\n", pstu->num, pstu->name);      
  printf("Sex = %c\nScore = %f\n\n", pstu->sex, pstu->score);      

}

posted on 2015-06-08 21:46  木屐  阅读(171)  评论(0编辑  收藏  举报

导航