#include<stdio.h>
int main()
{
int i,n=5;
for(i=0;i<n;i++)
{
printf("in of loop the value of i is %d\n",i);
}
printf("out of loop the value of i is %d",i);
}
我不明白为什么 i 的值在循环外显示为 5,但在循环中 i 的最后一个值为 4。
最佳答案
for 循环在指令 block 末尾递增 i 的值。因此,当 i = 4 时,循环运行,但最后 i = 4+1 = 5。此时,循环中的条件不再满足,因为 i 现在等于 5。
关于c - 为什么循环外i的值为5,但循环内i的最后一个值为4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871143/