c - Does For-Loop counter stay? -
simple question. imagine in ansi-c:
int i; for(i=0 ; i<5 ; i++){ //something... } printf("i %d\n", i);
will output "i 5" ?
is i
preserved or value of i
undefined after loop?
yes. if declared outside of loop remains in scope after loop exits. retains whatever value had @ point loop exited.
if declatred in loop:
for (int = 0 ; < 5 ; i++) { }
then undefined after loop exit.
Comments
Post a Comment