it compiled with no errors,warnings. but this wersion of code wont compile on my friends computer. it gives an error. multiple declaration of variable 'i' or something. i thought it is about our compiling options but i want to know what is difference . as i dont know how my teacher will compile it.
thanks in advance
It's because the scope of the variable i is limited to the first for loop. So after the loop the variable is destroyed and it does not exist to be referred to in the second loop.
Really, the second way is the right way, but I cannot possibly explain why vc++ 6 would allow the first copy to compile.
VC++ 6.0 is pre-standard. The standard added the rule that the scope of variables and objects declared in a block is limited to that block. Your version is the correct one.