#include<iostream>
using namespace std;
struct Teacher
{
char name[64];
int age;
};
int getTeacher(Teacher **p)
{
Teacher *temp = NULL;
if (p == NULL)
{
return -1;
}
temp = (Teacher *)malloc(sizeof(Teacher));
if (temp == NULL)
{
return -2;
}
temp->age = 33;
cout << "temp: " << temp << endl;
*p = temp;
cout << "p: " << p << endl;
cout << "*p: " << *p << endl;
cout << "&p: " << &p << endl;
}
int getTeacher2(Teacher* &myp)
{
myp = (Teacher *)malloc(sizeof(Teacher));
if (myp == NULL)
{
return -2;
}
myp->age = 36;
cout << "myp: " << myp << endl;
cout << "&myp: " << &myp << endl;
}
void FreeTeacher(Teacher * p)
{
free(p);
}
void main()
{
Teacher *pt1 = NULL;
getTeacher(&pt1);
cout << "&pt1: " << &pt1 << endl;
FreeTeacher(pt1);
cout << "-----------" << endl;
Teacher *pt2 = NULL;
getTeacher2(pt2);
cout << "&pt2: " << &pt2 << endl;
FreeTeacher(pt2);
cout << "-----------" << endl;
std::cout << "panht" << std::endl;
system("pause");
}
Test
最新推荐文章于 2022-10-10 23:09:05 发布