三元(条件)运算符用C [英] The ternary (conditional) operator in C

查看:174
本文介绍了三元(条件)运算符用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是需要条件运算符?在功能上是多余的,因为它实现了一个if-else结构。如果条件运算符是比同等的if-else分配更有效率,为什么不能的if-else是由编译器更有效地PTED间$ P $?

What is the need for the conditional operator? Functionally it is redundant, since it implements an if-else construct. If the conditional operator is more efficient than the equivalent if-else assignment, why can't if-else be interpreted more efficiently by the compiler?

推荐答案

三元运算符是一个语法和可读性的方便,而不是绩效快捷方式。人们都在它的优点分割为不同复杂程度的条件语句,但对于短的条件下,它可以是有一个一行前pression有用

The ternary operator is a syntactic and readability convenience, not a performance shortcut. People are split on the merits of it for conditionals of varying complexity, but for short conditions, it can be useful to have a one-line expression.

这篇关于三元(条件)运算符用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆