So, I just studied the Arrays material and got a problem...
I got this following code:
int a[5];
int i;
for(i=0; i<=10; i++) {
scanf("%d", &a[i]);
}
I declared on an array that its length is 5.
Then, I ran a for
loop from 0 to 10 that inserts numbers into a[i]
.
I used this table (which I created) to understand what happened during the execute time:
You see the red arrow? That's where the loop she be stopped, because they a[]
cannot get more than 5 values into it. Which mean, that a[6]
doesn't exist.
Even though, it keeps asking for numbers, and keeps saving them into the array.
One more thing, I'm currently using Dev C++ compiler.
Does anyone has an idea why is it happening?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…