【发布时间】:2021-09-12 18:53:51
【问题描述】:
我有一个非常基本的 C 程序,但对它的输出感到困惑:
#include<stdio.h>
int main() {
int i;
char s[] = "K";
for(i=0; s[i]; i++); {
printf("%d ", i);
printf("%c ", s[i]);
}
}
它将 i 值输出为 1,但根据该线程的答案之一: Difference between pre-increment and post-increment in a loop?
int i = 0; // Initialization
loopStart:
if (i < 5) // Condition
{
Output(i);
i++ or ++i; // Increment
goto loopStart;
}
在Output(i)之后发生增量(相当于printf("%d ", i);),那么i的值怎么是1而不是0呢?
【问题讨论】:
-
什么是输出?
-
我想,我忽略了分号,但它实际上让我看到了这个线程。 stackoverflow.com/questions/13421395/…,为了弄清楚发生了什么。