我看到一些代码如下:
struct Hello
{
int age;
int time;
int data[1];
};
struct Element
{
int a;
int b;
};
struct Element element_[5] = (/* Initiate the array */);
struct Hello* hello = (struct Hello*)malloc(sizeof(Element)*5);
struct Element * element_p = NULL;
element_p = (struct Element *)hello->data;
for(int i = 0; i<5; i++)
{
memcpy(element_p, &element_[i], sizeof(struct Element));
}
对于这一行:element_p = (struct Element *)hello->data;
,为什么我们需要强制转换hello->data to (struct Element *)
?这是否意味着对element_p
will指针的操作对hello->data
? 这一行是否会将每个元素的地址填充struct Element element_[5]
到 的每个元素hello->data
?