?
What is the output of the expression: "5" + "2" in Ruby?
Answer & Solution
Correct Answer:
Option
C
Question: What is the output of the expression: "5" + "2" in Ruby?
Explanation:
In Ruby, when you use the "+" operator with strings (text enclosed in double quotes), it performs string concatenation, not mathematical addition.
This means it joins the two strings together.
So, "5" + "2" combines "5" and "2" to create the new string "52".
Therefore, the correct answer is Option C: 52
Important Note: If you wanted to perform mathematical addition, you would need to use numbers without quotes, like 5 + 2, which would result in 7. But in this case, because the inputs are strings, Ruby treats the "+" as a string concatenation operator.
Explanation:
In Ruby, when you use the "+" operator with strings (text enclosed in double quotes), it performs string concatenation, not mathematical addition.
This means it joins the two strings together.
So, "5" + "2" combines "5" and "2" to create the new string "52".
Therefore, the correct answer is Option C: 52
Important Note: If you wanted to perform mathematical addition, you would need to use numbers without quotes, like 5 + 2, which would result in 7. But in this case, because the inputs are strings, Ruby treats the "+" as a string concatenation operator.
Join the Discussion
Login to post a comment or share your explanation.
Login