I have recently started to learn C and I am taking a class with C as the subject. I\'m currently playing around with loops and I\'m running into some odd behaviour which I d
You declare int array[10]
means array
has index 0
to 9
(total 10
integer elements it can hold). But the following loop,
for (i = 0; i <=10 ; i++)
will loop 0
to 10
means 11
time. Hence when i = 10
it will overflow the buffer and cause Undefined Behavior.
So try this:
for (i = 0; i < 10 ; i++)
or,
for (i = 0; i <= 9 ; i++)