结构体指针赋值
#include <stdio.h>
#include <windows.h>
struct regDevice {
int protocolId;
struct regDevice* next;
};
regDevice* firstMrfDataBufferDriver = NULL;
int main(int argc, char* argv[])
{
regDevice* mrfDataBufferDriver=NULL;
regDevice** prev;
mrfDataBufferDriver=(regDevice*)malloc(sizeof(regDevice));
mrfDataBufferDriver->next=NULL;
for (int i=0;i<10;i++)
{
mrfDataBufferDriver->protocolId=i;
prev = &firstMrfDataBufferDriver;
if (*prev != NULL) {
prev = &(*prev)->next;
}
*prev = mrfDataBufferDriver;
printf("%d\n",(*prev)->protocolId);
}
return 0;
}
为什么循环中,只有第一次i=0时,*prev才为NULL
其它次循环*prev就不等于NULL了呢
非常感谢