柔性数组--变长数组

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);
}

 

posted on 2014-11-09 22:51  程良  阅读(173)  评论(0编辑  收藏  举报

导航