Scope of variable declared inside a for loop

后端 未结 5 521
挽巷
挽巷 2020-11-30 15:18
for(int i=0; i<10;i++){
 int j=0;
}

Is j a block variable or a local variable? I see that j\'s scope is only till the for loop ends

5条回答
  •  猫巷女王i
    2020-11-30 16:11

    j variable is accessible inside {this block} only. That not only means that it can't be changed anywhere else, but also it is recreated every time loop loops.

提交回复
热议问题