38.指针指向栈区内存和堆区内存


#include
#include
#include
struct Student
{
	int age;
	char name[50];
	int score;
};
int main()
{
	//指针指向栈区空间 
	struct Student *p;
	struct Student tmp;
	p = &tmp;
	p->age = 18;
	strcpy(p->name, "mike");
	p->score = 59;
	printf("%d, %s, %d", p->age, p->name, p->score);
	printf("%d, %s, %d", tmp.age, tmp.name. tmp.score);
	
	//指针指向堆区空间
	struct Student *q;
	q = (struct Student*)mallloc(sizeof(struct student));
	if(p == NULL){
		printf("分配失败\n");
		return 0;
	}
	if(p != NULL){
		free(p);
		p = NULL;
	}
}