#include<stdio.h>
void main()
{
int i=10;
printf("%d %d %d\n",a,--a,++a); // output 10 10 10
}
这段代码如何给出相同的输出? 这些自增和自减运算符的优先级是什么?
最佳答案
C 像许多语言一样使用 Eager evalution ( https://en.wikipedia.org/wiki/Eager_evaluation )
这意味着 printf
的参数在调用 printf
函数之前被求值。
对于编译器来说,你的代码看起来像
#include<stdio.h>
void main()
{
int a=10;
a;
--a;
++a;
printf("%d %d %d\n",a,a,a); // output 10 10 10
}
关于c - 这个 printf() 函数如何输出这些值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36533769/