唯一的区别是->前面放的是指针,而.前面跟的是结构体变量。
如已定义了一个结构体struct student,里面有一个int a;
然后有一个结构体变量struct student stu及结构体变量指针struct student *p;
且有p=&stu,那么p->a和stu.a表示同一个意思:
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
int ch;
}tree;
typedef struct
{
int ch;
}school;
void main()
{
tree* node1=malloc(sizeof(tree)) ;
node1->ch=5;//这是在堆上开辟;
school s;
s.ch = 10;//这是在栈上开辟;
printf("%d", node1->ch);
printf("%d", node1.ch);//报错 node1是指针;
printf("%d", s.ch);
printf("%d", s->ch);//报错 s不是指针,s是变量名;
system("pause");
}