Please, can some one tell me what's wrong with this code?
#include <iostream>
using namespace std;
int main() {
int a[3], i;
for(i = 0; i <= 3; i++ )
{
a[i] = 0;
cout << "i = " << i << endl;
}
return 0;
}
The array length for this code is only
3but the for loop executes4times since the loop executes from 0 to 3. The value ofiwill look like this:Since the array
a[3]length is 3, but you tried putting4elements in it ofcourse it will show an error:Fixes
Try to change the array length or the loop condition.