C语言结构体,点运算和箭头运算

C语言有一种数据类型叫结构体,其定义格式为:

  struct 结构体名 {
    结构体成员变量定义;
  };
  如:
  struct student {
  char name[20];
  int age ;
  double score ;
  };

  用结构体定义的变量叫结构体变量,如:

      struct student stu; //定义一个结构体变量stu

  这种变量在引用结构体成员时,使用点(.)来操作,如:

  strcpy( stu.name, "zhangsan" );
  stu.age=20;
  stu.score=100;

  结构体类型也可以定义指针变量,如:

      struct student *pstu; //定义一个结构体指针变量pstu

      pstu=&stu ; //pstu指针指向stu结构体变量

  结构体指针变量在引用成员变量时,使用箭头(->)来操作,如:

  strcpy( pstu->name, "zhangsan" );
  pstu->age=20;
  pstu->score=100;

  以上这两种符号的使用是C语言的规定!

typedef struct abc
{int x;
int y;
int z;
}ABC;
是将结构体abc类型重新起个名字为ABC,以后再定义同一类型的变量时,可以写成:
ABC m,n;
与:
struct abc m,n;
作用是一样的。
可将复杂数据类型简单化

原文地址:https://www.cnblogs.com/judes/p/5719595.html