版本 1:
struct mydef_s1 {
int argc;
char *argv[3];
};
struct mydef_s1 *p1 = (struct mydef_s1*) malloc (sizeof (struct mydef_s1));
p1->argv[0] = malloc (8);
p1->argv[1] = malloc (16);
p1->argv[2] = malloc (24);
Now, I want to achieve above with the following structure declaration?
版本 2:
struct mydef_s2 {
int argc;
char **argv;
};
如果我是对的,那么下面只想分配 8 个字节(4 个用于内存指针,4 个用于我机器中的整数)
struct mydef_s2 *p2 = (struct mydef_s2*) malloc (sizeof (struct mydef_s2));
我该怎么做才能做到以下几点?
p2->argv[0]= malloc(4);
p2->argv[1]=malloc(8);