链表指针问题
程序代码:#include <stdio.h>
struct ListNode
{
int m_nKey;
ListNode * m_pNext;
};
unsigned int GetListLength(ListNode * head)
{
if (head == NULL)
return 0;
unsigned int length = 0;
ListNode * p = head;
while (p)
{
length += 1;
p = p->m_pNext;
}
return length;
}
int main(int argc, char *argv)
{
ListNode abc[5] =
{
{ 1,0 },
{ 2,0 },
{ 3,0 },
{ 0,0 },
{ 5,0 }
};
abc[0].m_pNext = &abc[1];
abc[1].m_pNext = &abc[2];
abc[2].m_pNext = &abc[3];
abc[3].m_pNext = &abc[4];
abc[4].m_pNext = &abc[5];
printf("\n In total,There %d dates\n", GetListLength(abc));
getchar();
return 0;
}为什么遍历链表个数的p 无法读取head的地址呢, 还有 我
程序代码:
ListNode abc[5] =
{
{ 1,0 },
{ 2,0 },
{ 3,0 },
{ 0,0 },
{ 5,0 }
};
abc[0].m_pNext = &abc[1];
abc[1].m_pNext = &abc[2];
abc[2].m_pNext = &abc[3];
abc[3].m_pNext = &abc[4];
abc[4].m_pNext = &abc[5];为什么不能放到主函数之外初始化









