It just happened to me. A bug. I set a 5 element array and a position variable to scroll through all its index:
int matematica[5];
int pos = 0;
and then I had my loop working just ok. Like this:
while (pos < 5) {
printf("Entre com o número da matrícula do %dº aluno: \n", pos+1);
scanf("%d", &num);
if (num != 35)
matematica[pos] = num;
pos++;
}
Everything working like a charm. After that, I had do the same to 150 positions, so I changed the while loop from while (pos < 5)
to while (pos < 150)
but forgot to do the same with the array. What happened then is the object of my question itself. The program didn't crash or something, it just happened that the printf
and scanf
statements run a bit more than 5 times then stops (sometimes 8 times, sometimes 7...)
Why does that happens. I of course fixed it later, but I still can't grasp the logic behind that bug.