C语言指针赋值
typedef struct{
union
{
void *P8Data;
}Content;
}SceneMemberStruct;
SceneMemberStruct* sceneMember=NULL;
uint8_t i=0;
uint8_t *p=NULL;
sceneMember = malloc(sizeof(SceneMemberStruct));
if (sceneMember)
{
p = sceneMember->Content.P8Data = (uint8_t*)malloc(2+installCode.numAttr*8);
if(sceneMember->Content.P8Data)
{
//第一种写法
*(uint8_t*)(sceneMember->Content.P8Data) = 60;
*(((uint8_t*)(sceneMember->Content.P8Data))+1) = installCode.numAttr;
//第二种写法
((uint8_t*)(sceneMember->Content.P8Data))[0] = 60;
((uint8_t*)(sceneMember->Content.P8Data))[1] = installCode.numAttr;
//第三种写法
i = 60;
((uint8_t*)(sceneMember->Content.P8Data)) = &i;
(((uint8_t*)(sceneMember->Content.P8Data))+1) = &installCode.numAttr;
//第四种写法
*p++ = 60;
*p++ = installCode.numAttr;
}
}
为啥前三种写法都没法把60赋值给P8Data所指向的地址空间?只有最后一种写法可以?
我理解的最后一种写法这是多定义p指针指向而已,
麻烦大神指导下