我已经使用Code :: Blocks查找结果了,它2在结尾处给出了i + j = 1 + 1。
#include <stdio.h>
int main(void) {
int i = -1, j = 1;
for(i++; i++; i++)
j++;
printf("%d",i + j);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
怎么i成为1,为什么j不增加?
我通过Code :: Blocks运行了它,并向我显示了最终答案1.然后在“ i = i-2 * TWO”语句中替换两个,为什么这样?
该代码是我要解决/理解的一项家庭作业的一部分:
#include <stdio.h>
#define ONE 1
#define TWO ONE + ONE
int main(void) {
int i = 2;
i = i - 2 * TWO;
printf("%d\n", i);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想了解为什么在if-else-if-else-if条件中,只要第一个if(condition)为true,其他所有随后出现的条件都会被忽略,程序会终止;为了使其实用,下面是用C语言编写的以下代码:
#include <stdio.h>
int main() {
int a = 10;
if (a == 5)
printf("Condition is false");
else if (a == 6)
printf("Condition is also false");
else if (a == 7)
printf("Condition is also false");
else if (a == 10)
printf("Condition is true");
else if (a == 9)
printf("Condition is also false");
else
printf("Condition is still false");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
例如,如果a为5而不是10,则首先if的结果为true,其余的else-如果作为一个整体被视为false ...如果a为10,则每个条件首先直到if(a == 10)的结果为false为止,if(a == 10)下的语句将被打印(因为条件为true),然后再次执行以下else-if和final else:所有被忽略。为什么不全部检查?
是因为在每个if之后,后面的else几乎像单个语句一样虚拟地考虑了其下方的所有内容,并像这样操作(就像将else后面的所有内容都放在花括号中一样)?