#include <iostream>
using namespace std;
struct Teacher
{
char name[64];
int age;
};
int getTe(Teacher **myp)
{
Teacher *p = (Teacher *)malloc(sizeof(Teacher));
if (p == NULL)
{
return -1;
}
memset(p,0,sizeof(Teacher));
p->age = 33;
*myp = p;
return 0;
}
int getTe1(Teacher* &myp)
{
Teacher *p = (Teacher *)malloc(sizeof(Teacher));
if (p == NULL)
{
return -1;
}
memset(p, 0, sizeof(Teacher));
p->age = 100;
myp = p;
return 0;
}
int main()
{
Teacher *p = NULL;
getTe(&p);
getTe1(p);
cout << p->age << endl;
return 0;
}
指针引用的基本应用
最新推荐文章于 2024-08-06 19:21:33 发布