伙计们,我是编程新手,我对后增量值的结果感到惊讶,现在我发现并执行了下面的代码后,如果 for 循环说 1.初始化 2.如果错误终止,检查条件 3.增量。 i++ 在哪里发生? i值在哪里等于1?
int main()
{
int i, j;
for (int i =0; i<1; i++)
{
printf("Value of 'i' in inner loo[ is %d \n", i);
j=i;
printf("Value of 'i' in outter loop is %d \n", j);
// the value of j=i is equals to 0, why variable i didn't increment here?
}
//note if i increments after the statement inside for loop runs, then why j=i is equals to 4226400? isn't spose to be 1 already? bcause the inside statements were done, then the incrementation process? where does i increments and become equals 1?
//if we have j=; and print j here
//j=i; //the ouput of j in console is 4226400
//when does i++ executes? or when does it becomes to i=1?
return 0;
}
如果Post increment使用的值加1?我迷路了...请解释...非常感谢。
最佳答案
我不太确定你在问什么,但有时如果重写为 while 循环,初学者更容易理解:
int i = 0;
while (i < 1)
{
...
i++; // equivalent to "i = i + 1", in this case.
}
关于c - 受困惑的束缚,需要明确解释职位增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17057031/