标题:有代码不懂,望大佬进来看看!
只看楼主
a75692074
Rank: 1
等 级:新手上路
威 望:1
帖 子:48
专家分:0
注 册:2018-7-20
结帖率:100%
 问题点数:0 回复次数:2 
有代码不懂,望大佬进来看看!
#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.

谢谢大神指导!!
搜索更多相关主题的帖子: 代码 int index for sizeof 
2018-08-13 12:16
Jonny0201
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:52
帖 子:488
专家分:2603
注 册:2016-11-7
得分:0 
sizeof days / sizeof days[0]
求数组长度
2018-08-13 14:08
a75692074
Rank: 1
等 级:新手上路
威 望:1
帖 子:48
专家分:0
注 册:2018-7-20
得分:0 
回复 2楼 Jonny0201
好,谢谢
2018-08-13 22:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-489171-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.561765 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved