New course! Every coder should learn Generative AI!
Try a free lesson0
How!!
[C++] int i=5; for(int i=0;i<7;i++) {} cout<<i; Output=5
1 Answer
+ 9
If you were wondering why the output is 5 instead of 7, the answer was that you have two variables named <i>, one outside the for loop (initialized to 5), and the other one was declared within the for loop scope (initialized to zero). You were incrementing the <i> that was declared inside for loop, which will not affect the first <i> that was declared outside the for loop.
Hth, cmiiw