#include <stdio.h>
void main()
{
int k = 8;
int m = 7;
int z = k < m ? k = m : m++;
printf("%d", z);
k = 8;
m = 7;
z = k < m ? m++ : k=m;
printf("%d", z);
}
输出
Compile Error:
main.c: In function 'main':
main.c:19:32: error: lvalue required as left operand of assignment
z = k < m ? m++ : k=m;
^
答案 0 :(得分:4)
由于?:
=
条件运算符与z = k < m ? m++ : k=m;
相比
z = ((k < m ? m++ : k) = m);
// ^^^^^^^^^^^^^^^^
// expression = m
等同于(或解析为):
m
{{1}}被分配给表达式 - higher precedence错误。
阅读Lvalue