What is the output of the expression: "5" + "2" in Ruby?
A. "7"
B. 7
C. 52
D. Error
Answer: Option C
Solution (By Examveda Team)
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.
Join The Discussion
Comments (1)
Related Questions on Data Types and Variables in Ruby

How is it possible. The answer should be 52.