What’s the difference between ternary and tertiary?

Tertiary The conditional operator ( condition ? consequence : alternative ) is often referred to as both the “ternary operator” and the “tertiary operator”. What’s the difference?

Ternary” means “having three parts”. Operators in C# can be unary, binary or ternary – they take one, two or three operands.

 “Tertiary” means “third in order”. Compiler flaws noted in bug reports can be of primary, secondary or tertiary importance. Colours can be primary (yellow), secondary (orange) or tertiary (yellowish-orange), like our muppet friend to the left there. And so on.

“Tertiary operator” is therefore an English usage error, unless what you’re trying to say is that the conditional operator is third most important to you, or that it is a lovely greenish-blue colour.

I say avoid the problem altogether; it is simply more clear to call the conditional operator “the conditional operator”.

Comments (26)

  1. Mike Greger says:

    I’ve always thought it was bluish-purple.

  2. bmm6o says:

    If you search for "tertiary operator" in Google, it suggests ‘Did you mean "ternary operator"?’  Which I’m surprised at, I thought they only suggested fixing spelling mistakes.  So they’re also doing their part to educate the masses.

  3. Andrew Hare says:

    Yes!  I am constantly saying this exact thing to others (in real life and on Stack Overflow).  It doesn’t help that some programming languages (I am looking at you, PHP) officially refer to the conditional operator as *the* ternary operator.

  4. Besides "the conditional operator" does c# have other ternary operators? (which would make "the ternary operator" ambiguous)

  5. brunomarques says:

    Hi Patrick, the "conditional operator" is the only ternary operator, hence why it’s usually called the ternary operator

  6. That’s what I thought.

    Perhaps it should be renamed to “THE Ternary Operator.”

    The trouble with “the ternary operator” is that it describes what it looks like, not what it does. This is why . + => are called the “member access operator”, “addition operator” and “lambda operator” and not the “dot operator”, “plus operator” and “fat arrow operator”.

    I note that one could argue that this form of the call operator “x(y,z)” is a ternary operator, but we actually characterize it as a binary operator between an invocable expression “x”, and an argument list “y,z”. — Eric

  7. zoldello says:

    This is a nice spot- short, sweet and void of pork. I wish Joel Spolsky and Jeff Atwood would read your blogs.

    First, they do. (Or, to my knowledge, Jeff does. I don’t know if Joel does; he and I haven’t chatted in a while.) Second, if you think my blog posts are short and concise, I suspect you haven’t been reading my blog very long. I was once given a singing fish as a joke prize for being “the guy who writes the most unnecessarily detailed excessively long emails”. And third, if you have a criticism to make of Joel or Jeff, I suggest you make it to them directly. Fourth, glad you like the blog. — Eric

  8. configurator says:

    So you agree that the operator is tertiary because of its colour?

    I suggest that all operators should be called tertiary for that reason. In fact, the word operator is redundant. In short,

    + the addition tertiary

    => the lambda tertiary

    and ?:, the ternary tertiary.

  9. Erik says:

    I once heard it called the ‘topiary operator’…

  10. Couldn’t && and || also be called “conditional operators” as thier behaviour (in dealing with the right hand side) is conditional on the value of the left hand side.

    Good point. Yes. Those operators are formally called the “conditional logic operators”, which I agree is potentially easily confused with “the conditional operator”. Usually it’s clear from context though. — Eric

  11. Brad the Code Monkey says:

    Where is the Ruth Buzzy(sp?) operator when you need it?

    (Laugh In…)

  12. Richard says:

    @Mike Greger: I’ve always thought it was bluish-purple.

    I would have thought that fluorescent greenish-yellow purple was closer to the mark, and explains why only wizards use it.

  13. Michael Liu says:

    Let’s call it "the ternary conditional operator".

  14. Pavel Minaev [MSFT] says:

    There is a short term with a long history of use that describes this operator precisely – "iif". So I guess it would be the "iif operator".

  15. Tom says:

    But iif itself is short for "inline if" and is provided in languages without a conditional ternary operator (e.g., Visual Basic).  Is it karmically sound to use shorthand to describe other shorthand?

  16. Mike Dunn says:

    I maintain that the correct term is “trinary.”  Unary, binary, trinary. Compare unicycle, bicycle, tricycle.

    Indeed, the OED lists “trinary” as a synonym for “ternary”, but notes that its usage is rare. They were apparently synonyms in Latin as well: trinarius and ternarius both have the sense of “three parts”.

    You can sometimes tell whether English words have a Latin or Greek origin based on whether the prefixes are uni-, bi-, tri- (Latin) or mono-, di-, tri- (Greek). Had the Romans invented bicycles they would have been unicyclus, bicyclus, tricyclus, as they are in English. The Greeks would have had μονοκύκλος, δικύκλος, τρικύκλος – monokyklos, dikyklos, trikyklos meaning “one circle”, “two circle”, “three circle” — Eric

  17. fred says:

    Is ternary operator primary to && and || conditional (shortcircuit) logical operators?

  18. Wil says:

    So in the statement

    x = a + b*c;

    is "=" in fact the tertiary operator, because it’s the third one to be performed?

    Brad the Code Monkey: I think you mean the Lily Tomlin operator.

  19. Anthony P says:

    I’ve always been partial to the Midnight Star Operator.

  20. PC says:


    How about bing search?

    it actually brings "Ternary operation – Wikipedia, the free encyclopedia". May be bing should get as intelligent as Google.

  21. Zac says:

    Typical … to the question of whether it should be called "tertiary" or "ternary", you suggest a third option.

  22. Muaz says:

    Basically, ternary or tertiary is not problem, problem is knowledge confusion when we want ot use them 100% accurate manner.

  23. I think we should *invent* a new operator in C# 5 that takes 3 operands – just to force the disambiguation. A bit like some of the words I’m sure have been invented purely for scrabble ;-p

  24. Bent Rasmussen says:

    Don’t you ever wish C# if-then-else was an expression type instead of a statement type so you could write

    return if (x < 0) -1 else if (x > 0) +1 else 0;

    and do complex nested if-then-else’s; multiple lines where appropriate.

    Anyway, that’s history.

    Just dying to learn about your plans for C# 5.

  25. Runefs says:

    @Bent I guess you misspelled F# (it’s spelled with an F not a C and the if is an expression)

  26. Gabe says:

    Is it too late to fix MSDN for the VS2010 release?

    From MSDN’s topic “Operators (C# Programming Guide)“:

    “One operator, the conditional operator (?:), takes three operands and is the sole tertiary operator in C#.”

    That error was the inspiration for this post; I’ve informed the documentation managers of the mistake but I’m sure they have higher priorities. They’ll get to it eventually. — Eric

Skip to main content