#include <stdio.h>
#include <stdlib.h>
typedef struct student{
int number;
int age;
}STUDENT,*PSTUDENT;
#define SIZE 10
int main(int argc, char *argv[])
{
int i=0;
PSTUDENT student = (PSTUDENT)malloc(sizeof(STUDENT)*SIZE);
//利用这种方法,避免多级指针的使用,其实可以理解分配了一个结构体
//常理来说,这个指针也是可以移动的,但是由于未申请,这样越界了
//由于加上了*SIZE这个,也就是说,编译器允许了你移动的范围,所以不需要考虑多级指针了
printf("size student = %d\n",sizeof(STUDENT));
printf("size pstudent = %d\n",sizeof(student));
return 0;
}
malloc 分配结构体数组思考
最新推荐文章于 2023-04-23 21:22:11 发布