在以下代码片段中,“x”值将被测试多少次?
int x;
for(x=0;x < 10; x++)
printf("%d",x);
对我来说,答案似乎是11,但我的模块说它是10?!我错过了什么?
最佳答案
十一,因为在调用 printf 之前,在每次循环迭代的开始 测试条件:
0 < 10 == true
1 < 10 == true
2 < 10 == true
3 < 10 == true
4 < 10 == true
5 < 10 == true
6 < 10 == true
7 < 10 == true
8 < 10 == true
9 < 10 == true
10 < 10 == false // exit from loop (printf not executed)
关于c++ - for循环的小疑问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4566030/