#include<iostream>
#include<string>
using namespace std;
struct student {
string name;
int score;
};
struct teacher {
string tname;
struct student Arry[5];
};
void allocatspace(struct teacher tarry[2], int len)
{
string nameseed = "ABCDE";
for (int i = 0; i <= len; i++)
{
tarry[i].tname = "teacher_";
tarry[i].tname += nameseed[i];
for (int j = 0; j < 5; j++)
{
tarry[i].Arry[j].name = "student_";
tarry[i].Arry[j].name += nameseed[j];
tarry[i].Arry[j].score = rand()%60+40;
}
}
}
void printfInfo(struct teacher tarry[2], int len){
for (int i = 0; i < len; i++)
{
cout << "老师数据" << tarry[i].tname << endl;
for (int j = 0; j < 5; j++)
{
cout << "学生数据" << tarry[i].Arry[5].name << endl;
cout << tarry[i].Arry[5].score;
}
}
}
int main(){
struct teacher tarry[2];
int len = sizeof(tarry) / sizeof(tarry[0]);
allocatspace(tarry, len);
printfInfo(tarry, len);
return 0;
}
这个代码为什么编译器会显示数组溢出啊