为什么i ++在数组中使用 [英] Why is the i++ used in arrays

查看:273
本文介绍了为什么i ++在数组中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>

int main()
{
    int myArray[5];     // array of 5 integers lol
    int i;
    for (i=0; i<5; i++ )  // 0 - 4
    {
        std::cout << "Value for myArray[" << i << " ]: ";
        std::cin >> myArray[i];
    }
    for (i = 0; i<5; i++)
    std::cout << i << ": " << myArray[i] << std::endl;
    return 0;
}

为什么这个程序需要i ++?

Why is i++ required for this program to work?

推荐答案

$ c> i ), i 将保留 0 ,条件 i < 5 将永远保持真实,循环永远不会结束。

Because if you don't execute i++ (or any other statement which increments i), i will remain 0, the condition i < 5 will always remain true and the loop will never end.

这篇关于为什么i ++在数组中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆