struct Person
{
int m_Age;
};
void allocatMemory(Person **p) //**p具体person本体 *p对象的指针 p指针的指针
{
*p = (Person *)malloc(sizeof(Person));
(*p)->m_Age = 200;
}
void test01()
{
Person *p = NULL;
allocatMemory(&p);
cout << "Person is age: " << p->m_Age << endl;
}
//利用指针引用开辟空间
void allocatMemoryByRef(Person* &p)
{
p =(Person *)malloc(sizeof(Person));
p->m_Age = 1000;
}
void test02()
{
Person *p = NULL;
allocatMemoryByRef(p);
cout << "p的年龄" << p->m_Age << endl;
}
int main()
{
test01();
test02();
return 0;
}