C++ 指针引用

扫码查看
//指针引用
#include<iostream> using namespace std; struct Teacher{
char name[];
int age;
}; int InitA(Teacher **pout/*out*/){
int ERRO_MSG = ;
if (pout==NULL)
{
ERRO_MSG = ;
printf("pout==NULL erro msg:%d\n", ERRO_MSG);
return ERRO_MSG;
}
Teacher* ptemp = (Teacher*)malloc(sizeof(Teacher));
if (ptemp == NULL)
{
ERRO_MSG = ;
printf("内存分配失败! erro msg:%d\n", ERRO_MSG);
return ERRO_MSG;
}
ptemp->age = ;
*pout = ptemp;
return ERRO_MSG;
} //指针引用
int InitB(Teacher* &pout){
int ERRO_MSG = ;
pout = (Teacher*)malloc(sizeof(Teacher));
if (pout == NULL)
{
ERRO_MSG = ;
printf("内存分配失败! erro msg:%d\n", ERRO_MSG);
return ERRO_MSG;
}
pout->age = ;
return ERRO_MSG;
} void main(){
Teacher *p = NULL;
int ret = ;
//ret=InitA(&p);
//if (ret!=0)
//{
// printf("初始化Teacher失败!\n");
//}
//printf("教师A的年龄是%d\n",p->age);
ret = InitB(p);
if (ret != )
{
printf("初始化Teacher失败!\n");
}
printf("教师B的年龄是%d\n", p->age);
system("pause");
}
05-11 19:58
查看更多