If a function uses the ternary operator to compute the max, what would m be if a=4 and b=7?

Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

If a function uses the ternary operator to compute the max, what would m be if a=4 and b=7?

Explanation:
Ternary operator usage here picks between two values based on a condition: m = (a > b) ? a : b. It returns the first value if the condition is true, otherwise the second value. With a = 4 and b = 7, the condition 4 > 7 is false, so the operator selects b, which is 7. Therefore, m becomes 7. The other options don’t fit: 4 would require a > b to be true, 0 isn’t derived from this comparison, and selecting a would mean the condition was true, which it isn’t.

Ternary operator usage here picks between two values based on a condition: m = (a > b) ? a : b. It returns the first value if the condition is true, otherwise the second value. With a = 4 and b = 7, the condition 4 > 7 is false, so the operator selects b, which is 7. Therefore, m becomes 7. The other options don’t fit: 4 would require a > b to be true, 0 isn’t derived from this comparison, and selecting a would mean the condition was true, which it isn’t.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy