1. 程式人生 > >指標實現取出結構體變數中的成員

指標實現取出結構體變數中的成員

#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;
}