指针实现取出结构体变量中的成员

#include <stdio.h>

struct Student
{
  int age;
  float score;
  char sex;
};

int main(void)
{
  struct Student st = {80, 66.6F, 'F'};
  struct Student st2;
  st2.age = 10;
  st2.score = 88.8f;
  st2.sex = 'F';
  struct Student *pst = &st;
  st.age = 100;
  pst->score = 99.9f;
  (*pst).sex = 'M';
  printf("%d %f %c\n",st.age, pst->score, (*pst).sex);
  printf("%d %f %c\n",st2.age, st2.score, st2.sex);
  return 0;
}

posted @ 2018-11-04 10:47  冰韵不徙  阅读(1023)  评论(0编辑  收藏  举报