我发现了一些代码,对于循环如何退出以及它是如何工作的感到困惑。这个程序是否产生确定性输出?
我感到困惑的原因是:
1. `someArray` is of size 2, but clearly, the loop goes till size 3,
2. The value is deterministic and it always exits `someNumber` reaches 4
有人能解释一下这是怎么发生的吗?
当我在包含库名称时使用尖括号<>
,代码打印不正确。
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
int main() {
int someNumber = 97;
int someArray[2] = {0,1};
int findTheValue;
for (findTheValue=0; (someNumber -= someArray[findTheValue]) >0; findTheValue++) {
}
printf("The crazy value is %d", findTheValue);
return EXIT_SUCCESS;
}