malloc 分配结构体数组思考

#include 
#include 

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

你可能感兴趣的:(C,include,编译器,struct)