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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -