运算符优先级 - 示例 [英] Operator Precedence - sample
本文介绍了运算符优先级 - 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
main(){
int i,j,k;
k =(i = 4 ,j = 5 );
printf( k =%d,k);
return 0 ;
}
哪个获得了优先权以及如何获得?
解决方案
< blockquote>输出 k = 5
因为:
- 编译告诉我。
- 这是怎么回事逗号运算符工作,即:[逗号]是一个二进制运算符,它计算其第一个操作数并丢弃结果,然后计算第二个操作数并返回该值(和类型)(参见维基百科的Comma运营商 [ ^ ])。 因此评估步骤为:
-
i = 4
(丢弃) -
j = 5
(已退回) -
k = 5
(k
获取逗号运算符的返回值)
转到此链接,你会知道 pr-order ecedence-in-c-programming-language [ ^ ]
main(){
int i,j,k;
k = (i = 4, j = 5);
printf("k = %d", k);
return 0;
}
which gets the prcedence and how ?
解决方案
output isk = 5
because:
- Compiler told me.
- This is how comma operator works, namely: "[comma] is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type)" (see Comma operator at Wikipedia[^]).
Hence evaluation steps are:
i = 4
(discarded)j = 5
(returned)k = 5
(k
gets the returned value of the comma operator)
Go to this link and you will know the order-of-precedence-in-c-programming-language[^]
这篇关于运算符优先级 - 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文