创建链表两个指针看不懂,pEnd与pNew
struct Student* Create() {
struct Student* pHead=NULL;
struct Student* pEnd,*pNew;
iCount=0;
pEnd=pNew=(struct Student*)malloc(sizeof(struct Student));
printf("please first enter Name ,then Number\n");
scanf("%s",&pNew->cName);
scanf("%d",&pNew->iNumber);
while(pNew->iNumber!=0)
{
iCount++;
if(iCount==1)
{
pNew->pNext=pHead;
pEnd=pNew;
pHead=pNew;
}
else
{
pNew->pNext=NULL;
pEnd->pNext=pNew;
pEnd=pNew;
}
pNew=(struct Student*)malloc(sizeof(struct Student));
scanf("%s",&pNew->cName);
scanf("%d",&pNew->iNumber);
}
free(pNew);
return pHead;
}
//pEnd与pNew从pEnd=pNew=(struct Student*)malloc(sizeof(struct Student))中不是得到同一块内存的地址吗,操作任意一个指针变量等于操作一块内存,我感觉就是拿着一个地址穿来穿去,就被掉包了,就好像两个指针变量的指向变成了指向不同内存了,绕晕了