求助:结构体地址问题
为什么只输出了head->lili->20->
后面的两个学生信息为什么不能输出呢?
#include <iostream>
#include<cstring>
#include<iomanip>
using namespace std;
struct student
{
char name[20];
int age;
student* next;
}stu[3] = {{"lili",20,NULL},{"yoyou",23,&stu[2]},{"KO",19,&stu[1]}};
int main()
{
student* head = &stu[0];
student* p = head;
cout<<" Head->";
while(p)
{
cout<<(*p).name<<"->"<<(*p).age<<"->";
p = (*p).next;
}
cout<<endl;
}
为什么只输出了head->lili->20->
后面的两个学生信息为什么不能输出呢?
struct
[解决办法]
第一个结点的next是null 还怎么输出啊
stu[3] = {{"lili",20,&stu[1]},{"yoyou",23,&stu[2]},{"KO",19,NULL}};