这个程序的输出是什么以及如何?
#include<stdio.h>
int main(){
int a=0,b=10;
a=b---
printf("the value of b=%d",b);
printf("the value of a=%d",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在你的代码中,写作
a=b---
printf("the value of b=%d",b);
Run Code Online (Sandbox Code Playgroud)
和...一样
a = b---printf("the value of b=%d",b);
Run Code Online (Sandbox Code Playgroud)
这是一个具有未定义行为的表达式 ,因为尝试b在两个子表达式中更改和使用变量的值,而两个子表达式之间没有序列点.因此,此代码的输出无法证明.
没有上述问题,通常,语法类似于
x = (y--) - (<return value of printf() call>)
Run Code Online (Sandbox Code Playgroud)
这是一个完全有效的语法.
注意:
为什么a = b---<something>被视为a = (b--) - <something>和不是 a = b - -- <something>由于最大的蒙克规则.