柔性数组--变长数组
int init_Department(manager *pt)
{
assert( NULL != pt && pt->p != NULL) ;
pt->p->Manager = 10;
pt->p->PM =100;
pt->p->ProgrammerNo[0]=10000;
pt->p->ProgrammerNo[1]=10001;
pt->p->ProgrammerNo[2]=10002;
pt->p->ProgrammerNo[3]=10003;
pt->p->ProgrammerNo[4]=10004;
return 0;
}
typedef struct _Department
{ int Manager; int PM; int ProgrammerNo[0]; }Department; typedef struct _manager{ Department *p; }manager; int main(void) { printf("sizeof(Department)=%d\n",sizeof(Department)); Department *pt = NULL; int Num = 5; pt = (Department *)malloc(sizeof(Department) + sizeof(int) * Num); pt->ProgrammerNo[0] = 006; pt->ProgrammerNo[1] = 99; manager *ptr = ( manager *)malloc(sizeof(manager)); ptr->p=(Department*)malloc(sizeof(Department)+sizeof(int)*5); init_manager (ptr); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。