I am a bit puzzled, since it seems that the C++ Debugger in VS2010 is behaving a bit oddly. If I go about and run this:
int i = 100;
for(int i = 0; i < 5; i++)
{
printf("Value of i inside loop: %d", i);
}
printf("Value of i outside loop: %d", i);
then, when breakpointing on a line after the last one above and hovering the cursor above the "i" variable, the debugger shows the value 5.
However, if I decide to send the "i" variable as a parameter to a method:
Test(100);
void Test(int i)
{
for(int i = 0; i < 5; i++)
{
printf("Value of i inside loop: %d", i);
}
printf("Value of i outside loop: %d", i);
}
then, when breakpointing on the last line and hover with the mouse on "i", I, the debugger shows the value 100.
Could anyone enlight me on this (or test on your machine). Is it a bug or a feature or am I missing something?
Thanks in advance!
UPDATE: just to make things clear - actual program prints and executes as intended, it is only the debugger that shows unexpected values. So, one can ignore it says "printf", it could have been almost anything involving the variable "i".
iin theforloop to something else, likecounter. I think this should sort it for you.