| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1327 人关注过本帖
标题:有代码不懂,望大佬进来看看!
只看楼主 加入收藏
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
快速回复:有代码不懂,望大佬进来看看!
数据加载中...
 
   



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

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