Nested Local Variables
One difference between C and C++ is that in C++ you can declare a local variable anywhere. C only lets you declare at the start of a block. As soon as executable code is found in that block, you can no longer declare any more variables.However you can start a new block inside a block. This example has been tested in MS VC++ and GCC. The innermost j only exists in the block so assigning 4 does not affect the loop variable j in the for loop. The j++ however does, so the value printed out is 13.
int main(int argc, char * argv[])
{
int j;
j=0;
for (j=9;j<12;j++)
{
{
int j;
j=4;
}
}
{j++;}
printf("Value of j = %d",j) ;
return 0;
}



