0

Regarding C#,

To my understanding the question below is wrong. meaning that a "ternary operator" and a "conditional operator" . Am I Correct?

Question# 6: 10 > 9 ? “10 is greater than 9” : “9 is greater than 10” is an example of _______

  • Ternary operator
  • Conditional operator
  • Greater than operator
  • Inverse operator

Correct Answer: Ternary operator

http://www.tutorialsteacher.com/online-test/view-answer?test=csharp&que=6

AK_
  • 7,981
  • 7
  • 46
  • 78
  • 1
    Not sure if that's what you are asking, but it's the `?` that is the ternary operator, not the comparison (conditional). – 500 - Internal Server Error Aug 15 '17 at 22:32
  • 3
    Well that's a bad question, [MS themselves](https://msdn.microsoft.com/en-us/library/e4213hs1.aspx) clearly calls it *both* conditional operator and ternary operator. And there's a "greater than" in there as well.. – harold Aug 15 '17 at 22:32
  • 3
    According to [MSDN](https://msdn.microsoft.com/en-us/library/zakwfxx4(v=vs.100).aspx) You can call `?:` indeed Conditional or Ternary. It is not unlikely, however, that in your course material, _Conditional_ refers to `If`, while _Ternary_ sepcifically refers to `?:` – oerkelens Aug 15 '17 at 22:34
  • 4
    A ternary operator is just one with three arguments, the conditional operator is also a ternary operator. It is commonly called 'the' ternary operator though. – Lee Aug 15 '17 at 22:35
  • 1
    The distinction is subtle, but valid. The conditional operator (`?`) is a type of `ternary` operator, as it takes three parameters. Note that `Ternary (from Latin ternarius) is an adjective meaning "composed of three items"`. And that it's commonly used as such does not make it correct. – DonBoitnott Aug 15 '17 at 22:37
  • 1
    The question is rather dumb and it could be one of those questions that ask for the "most correct" choice. – Devin L. Aug 15 '17 at 22:39
  • edited the title to clarify – AK_ Aug 15 '17 at 22:42
  • 2
    That's the only question on that site that you have a problem with? I just went through the test, and putting the horrible grammar aside, the questions/answers are mostly pathetic. Stuff like "what's the correct way to initialize an array?" `int[] array = new int[5];` or `int[] array = new int[] { 1, 2, 3, 4, 5};` Well guess what; they're both correct! There were at least 4 other questions that were, at best, misleading. That site should be taken down before it harms any more future programmers. – itsme86 Aug 15 '17 at 22:51
  • 6
    Those questions are pretty much all horrid. Never go back to that site. – Eric Lippert Aug 15 '17 at 23:08
  • @EricLippert Thanks! could you direct me at a site with descent C# questions? – AK_ Aug 16 '17 at 00:05
  • 2
    @AK_: I could not. I'm not a big fan of this format. Mastery of programming languages is not measured by the amount of trivia you have memorized; it's about understanding the concepts, how they relate logically to one another, and how to use language elements to build new, powerful, elegant, useful abstractions. – Eric Lippert Aug 16 '17 at 00:09
  • @EricLippert a friend of mine is using it as a practical way to prepare for job interview. Also, I'm not sure I agree. you're right, these tests are useless for learning. but as to tool to verify you understand basic concepts? – AK_ Aug 16 '17 at 00:16
  • @oerkelens - while "if" may be a conditional, it is not a conditional operator. –  Mar 18 '19 at 02:55

1 Answers1

2

The correct answer is "Conditional Operator" ( which happens to be the only ternary operator so often gets called that ) as that's what the language reference calls it.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • is the issues that its the Ternary operator in java and on the quest to be !java things in get garbled with how programmers are used to labeling things – snowCrabs Aug 15 '17 at 23:09
  • In Java, ```?:``` is called [the conditional operator](https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.25). It's true that since the conditional operator is the only ternary operator, one can unambiguously refer to it as *the* ternary operator, but that doesn't mean that 'ternary operator' is its name. –  Mar 18 '19 at 02:53
  • 1
    @KeithNicholas - my comment was directed to snowCrabs, who asked "is the issue that it's the ternary operator in Java?", and what I'm saying is that *it isn't* called the ternary operator in Java either. We're saying the same thing, you about C# and me about Java. Possibly I should have stopped after my first sentence and it would have been clearer. If you'd prefer, we can delete these comments and then I'll re-post, reworded, –  Mar 18 '19 at 03:07