Conditional or Ternary operator

Sep 30, 2009 at 8:04pm
closed account (z05DSL3A)
I don't want to a noise to to the artical How to use the Conditional (ternary) operator: So I am posting this here.

It would appear that some people know the ?: operator as the Ternary operator, rather than the Conditional operator, that every text I have every read refers to it.

I was just wondering how people refer to it and why?
Sep 30, 2009 at 9:31pm
I refer to it as either the ternary operator or the "question mark-colon" operator. XD Didn't know you could call it the conditional operator.
Sep 30, 2009 at 10:15pm
I've always referred to it as the ternary operator.... I rarely use it. All the books I have refer to it as the ternary operator.
Oct 1, 2009 at 5:49pm
I read it as "ternary operator" in K&R. I didn't know it was also anything different. Grey Wolf enlightened me so I changed the title of the article.
Oct 1, 2009 at 6:39pm
closed account (z05DSL3A)
I read it as "ternary operator" in K&R.

I asume you are referring to page 51 (if we have the same edition) were it does say
The conditional expression, written with the ternary operator "?:"

I find this misleading, I read that as the ?: operator is a ternary operator; meaning it takes three arguments.

If you look in the reference section (appendix A), you will find it under A7.16 Conditional operator on page 208.

Oct 1, 2009 at 7:23pm
Oh. I'm not sure about what edition I have. I wasn't thinking of "ternary" as having three operands! That never crossed my mind. I knew of unary operators but I didn't know there could be such a thing as ternary meaning three operands. What, then, would you call an operator that takes two operands (e.g. assignment operators)?
Oct 1, 2009 at 8:11pm
What, then, would you call an operator that takes two operands (e.g. assignment operators)?


I guess that would be binary operators.
Oct 2, 2009 at 12:11pm
That's what I was thinking...
Oct 8, 2009 at 1:53am
The two books I have refer to it as the conditional operator. I think that I picked up the term ternary from the internet and from conversations with other programers who referred to it as the ternary operator. Some websites refer to it as such. In the C++ std it is the conditional operator so that term seems to be the official name. Ternary means composed of three things so I can see how the nickname "ternary operator" came about. The name ternary operator is more descriptive to me and helps me remember how it works. When I first started using it I kept having to consult a reference to remember how to structure it. Once I picked up the term ternary operator it stuck in my head a little better. The "conditional operator" doesn't help me visualize what it does.
Last edited on Oct 8, 2009 at 1:55am
Oct 8, 2009 at 2:38am
Both terms work for me -- I tend to use what the natives will grok. After all, there is only one ternary operator... (And yes, for those of you paying attention, there is an N-ary operator, which can also take three arguments, but it is not restricted to three: hence, it is N-ary and not ternary.)

:-]
Topic archived. No new replies allowed.