c - 受困惑的束缚,需要明确解释职位增量

标签 c

伙计们,我是编程新手,我对后增量值的结果感到惊讶,现在我发现并执行了下面的代码后,如果 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/

相关文章:

c - 将 strcmp 与 char 和 struct 数组一起使用时出错

c - 使用 Realloc 超过 3 次时出现段错误

java - 如何使用 swig 调用需要来自 Java 的结构数组的 C 函数?

c - gcc 可能的错误?带有点符号的结构中缺少初始值设定项

c++ - 这是一个有效的 C 语句吗?

c - ioctl KVM_RUN 在什么情况下返回?

c - 将二维数组作为参数传递

c - 使用数组的堆栈实现

c++ - 将大 POD 类型转换成小 POD - 保证有效?

C UDP服务器访问问题