#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;
typedef struct teacher{
int id;
char name[64];
} teacher;
int getTeacher(teacher** pp_teacher){
*pp_teacher=(teacher*)malloc(sizeof(teacher));
if(*pp_teacher!=NULL){
(*pp_teacher)->id=100;
strcpy((*pp_teacher)->name,"xixi");
return 1;
}
return -1;
}
void freeTeacher(teacher** pp_teacher){
if(*pp_teacher!=NULL){
free(*pp_teacher);
*pp_teacher=NULL;
}
}
int getTeacher_(teacher* &p_teacher){
p_teacher=(teacher*)malloc(sizeof(teacher));
if(p_teacher!=NULL){
p_teacher->id=100;
strcpy(p_teacher->name,"haha");
return 1;
}
return -1;
}
void freeTeacher_(teacher* &p_teacher){
if(p_teacher!=NULL){
free(p_teacher);
p_teacher=NULL;
}
}
int main()
{
teacher* p_teacher=NULL;
getTeacher(&p_teacher);
cout<<p_teacher->id<<" "<<p_teacher->name<<endl;
freeTeacher(&p_teacher);
cout<<"--------------------------------"<<endl;
getTeacher_(p_teacher);
cout<<p_teacher->id<<" "<<p_teacher->name<<endl;
freeTeacher_(p_teacher);
return 0;
}