小编lxw*_*lxw的帖子

数组上的C++ for循环

我发现了一个非常奇怪的c ++代码.有人可以为我解释for循环条件吗?
为什么它只有一个数组和索引变量?

include <iostream>

using namespace std;

int main()
{
   int a[] = {1, 2, 3, 4, 5};

   for (int i = 0; a[i];i++){
      cout << a[i] << endl;
   }

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

结果是:

1

2

3

4

-858993460

2424376

12655176

1

3492888

3483368

1402216725

为什么输出12个元素?那些额外的7个元素来自哪里?非常感谢!

c++ arrays indexing for-loop conditional-statements

0
推荐指数
1
解决办法
3951
查看次数

标签 统计

arrays ×1

c++ ×1

conditional-statements ×1

for-loop ×1

indexing ×1