ExamVeda
Login
Home
Data Types and Variables in Ruby
?

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.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Rachan N
Rachan N 2 years ago
How is it possible. The answer should be 52.