注册 登录
编程论坛 C++教室

有代码不懂,望大佬进来看看!

a75692074 发布于 2018-08-13 12:16, 1593 次点击
#include <iostream>
using namespace std;

int main()
{
    const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31};
    int index;

    for (index = 0; index < sizeof days / sizeof days[0]; index++)
        cout << "Month " << index + 1 << " has " << days[index] << " days.\n";
    cout << endl;
    return 0;
}

这一段不懂
for (index = 0; index < sizeof days / sizeof days[0]; index++)

有大神可以解释一下吗??

然后输出为什么是
Month 1 has 31 days.
Month 2 has 28 days.
Month 3 has 31 days.
Month 4 has 30 days.
Month 5 has 31 days.
Month 6 has 30 days.
Month 7 has 31 days.
Month 8 has 31 days.
Month 9 has 30 days.
Month 10 has 31 days.

谢谢大神指导!!
2 回复
#2
Jonny02012018-08-13 14:08
sizeof days / sizeof days[0]
求数组长度
#3
a756920742018-08-13 22:19
回复 2楼 Jonny0201
好,谢谢
1