【发布时间】:2021-04-17 13:49:28
【问题描述】:
我注意到一种我无法解释的行为。 `
typedef unsigned char mac_address_t[6];
mac_address_t* c = malloc(sizeof(mac_address_t));
printf("%p \n", c);
printf("%p \n", (*c));`
打印的值是一样的。 另一种打印值的方法是
printf("%p \n", &(*c)[0]);
不过这个我能理解,先start访问数组,然后[]访问数组的元素。在这种情况下,我无法理解 c 和 *c 背后的逻辑。此外,如果值相同,为什么我不能 c[i] 访问元素? 有人可以帮助我吗?
【问题讨论】:
-
不要 typedef 数组类型,以免造成混淆。像这样的 Typedef 是非常糟糕的做法,您只是发现了许多原因之一。