C语言结构体指针数组初始化问题
我的结构体定义代码:typedefstructaaAA;typedefstructbbBB;typedefAA*PAA;typedefAA*PAAS[500];typed...
我的结构体定义代码:
typedef struct aa AA;
typedef struct bb BB;
typedef AA *PAA ;
typedef AA *PAAS[500];
typedef PAAS *PPAAS;
typedef BB *PBB ;
typedef BB *PBBS[500];
struct aa{
char* name;
int age;
}
struct bb{
int aacount;
PBBS pbbs;
}
定义了一个变量:
PPAAS ppaas;
怎么对ppaas进行初始化?
上面写错了,应该是
定义类型
typedef PBBS *PPBBS;
定义变量
PPBBS ppbbs;
对ppbbs进行初始化 展开
typedef struct aa AA;
typedef struct bb BB;
typedef AA *PAA ;
typedef AA *PAAS[500];
typedef PAAS *PPAAS;
typedef BB *PBB ;
typedef BB *PBBS[500];
struct aa{
char* name;
int age;
}
struct bb{
int aacount;
PBBS pbbs;
}
定义了一个变量:
PPAAS ppaas;
怎么对ppaas进行初始化?
上面写错了,应该是
定义类型
typedef PBBS *PPBBS;
定义变量
PPBBS ppbbs;
对ppbbs进行初始化 展开
1个回答
展开全部
//给空值
ppaas = NULL;
//申请空间
ppaas =(PPAAS)new aa *[500];//new以后,这个空间(数组)存放500个指针,ppaas 指向这个空间,使用时需要再对每个元素去分配内存。
//比如
(*ppaas)[0] = new aa;
(*ppaas)[0]->age = 100;
(*ppaas)[0]->name = "sdfsdf";
//---------------------------------------------------
ppbbs = NULL;
ppbbs =(PPBBS)new PBB[500];
(*ppbbs)[0] = new BB;
(*ppbbs)[0]->aacount = 100;
(*ppbbs)[0]->pbbs[0] =new BB;
(*ppbbs)[0]->pbbs[0]->aacount = 101;
(*ppbbs)[0]->pbbs[0]->pbbs[0] = NULL;
(*ppbbs)[0]->pbbs[0]->pbbs[1] = NULL;
(*ppbbs)[0]->pbbs[1] = new BB;
(*ppbbs)[0]->pbbs[1]->aacount = 101;
(*ppbbs)[0]->pbbs[1]->pbbs[0] = NULL;
(*ppbbs)[0]->pbbs[1]->pbbs[1] = NULL;
(*ppbbs)[0]->pbbs[2] = NULL;
(*ppbbs)[1] = NULL;
ppaas = NULL;
//申请空间
ppaas =(PPAAS)new aa *[500];//new以后,这个空间(数组)存放500个指针,ppaas 指向这个空间,使用时需要再对每个元素去分配内存。
//比如
(*ppaas)[0] = new aa;
(*ppaas)[0]->age = 100;
(*ppaas)[0]->name = "sdfsdf";
//---------------------------------------------------
ppbbs = NULL;
ppbbs =(PPBBS)new PBB[500];
(*ppbbs)[0] = new BB;
(*ppbbs)[0]->aacount = 100;
(*ppbbs)[0]->pbbs[0] =new BB;
(*ppbbs)[0]->pbbs[0]->aacount = 101;
(*ppbbs)[0]->pbbs[0]->pbbs[0] = NULL;
(*ppbbs)[0]->pbbs[0]->pbbs[1] = NULL;
(*ppbbs)[0]->pbbs[1] = new BB;
(*ppbbs)[0]->pbbs[1]->aacount = 101;
(*ppbbs)[0]->pbbs[1]->pbbs[0] = NULL;
(*ppbbs)[0]->pbbs[1]->pbbs[1] = NULL;
(*ppbbs)[0]->pbbs[2] = NULL;
(*ppbbs)[1] = NULL;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询