An uninitialized variable holds garbage, so trying to use it may be considered a logic error.
Compilers may issue a warning when they detect that and you can translate such warnings to compile errors. However it is not a requirement, and the detection may fail.
gcc fails in this, clang reports it correctly
1 2 3
int foo;
for(int K=0; K<foo; ++K) //here
foo += K; //and here
both fail in
1 2 3
int foo[2];
for(int K=0; K<42; ++K)
foo[0] += foo[1];
By the way, you've got another error. In the loop of line 20 you are trying to access `c' out of bounds
(valid index are from 0 to 1000000)
So how does it(a compiler which doesn't detect the error) interpret an uninitialized variable?
For example in the case 1 you were telling about, how does clang interprets the value of foo?