我发现了一个非常奇怪的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个元素来自哪里?非常感谢!