struct定義了50組后超過50組為什么還能正常
struct Student
{
? ? int math;
? ? int english;
};
struct Student stu[50];
? ? srand((int)time(0));
? ? //為其中一個學(xué)生的成績隨機(jī)賦值
? ? for (int i = 0; i < 55; i++)
? ? {
? ? ? ? int a = random(1, 10);
? ? ? ? int b = random(1, 10);
? ? ? ? stu[20].math = a;
? ? ? ? stu[20].english = b;
? ? ? ? printf("%d=,%d,%d\n",i, stu[20].math, stu[20].english);
? ? }
我定義了50組,for循環(huán)54,超出4組,為什么還能正常運(yùn)行呢?長度難道是自增長的嗎?那還定義多少組有什么意義?
2023-03-11
并不是自己增長得哦。如果超出的不多,那么是可以運(yùn)行的。但如果超出的非常多,會給你報錯。正常來說你輸出的內(nèi)容應(yīng)該是0吧?因?yàn)椴]有定義。你這個代碼是越界的,是有錯誤的,不報錯不代表是對的。
2022-03-06
正常云行但是輸出不了吧