Skip sliders in a for loop:
for (i=0;i<5;i++);
For your logic, you don't need a sym-colon after a for loop.
Due to the semi-colony, the for-loop is evaluated 5 times, and by the time printf
reached, the value of i
is 5. Now, trying to access index 5 in the array gives you an unknown value, since you initialized the array with only 5 values. This may become clearer if you were to print the value of i
in the printf statement:
for (i=0;i<5;i++); { printf("i: %d \t Val: %d",i, array[i]); }
Gives you the result, for example:
i: 5 Val: 32767
source share