版本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;
};
如果我正確的,那麼下面想在內存指針& 4分配僅8個字節(4整我機)
struct mydef_s2 *p2 = (struct mydef_s2*) malloc (sizeof (struct mydef_s2));
什麼sho我需要做以下事情嗎?
p2->argv[0]= malloc(4);
p2->argv[1]=malloc(8);
你是不是指'p1-> argv [2] = malloc(24);'? –
看起來像一個可怕的想法。你怎麼知道數組中每個條目分配塊的時間長度?可能是XY問題。你實際上想要達到什麼目標? – Olaf