#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++ 才能运行?
最佳答案
因为如果你不执行 i++
(或递增 i
的任何其他语句),i
将保留 0
, 条件 i < 5
将始终保持为真,循环永远不会结束。
关于c++ - 为什么i++用在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6313669/