Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Basics and Runtime
What is the output of this Ruby code?
print "Hi"
puts " There"
p "!"
AHiThere "!"
BHi There !
CHi There!"\n"
DHi There "!"
Step-by-Step Solution
Solution:
  1. Step 1: Analyze print and puts output

    print "Hi" outputs "Hi" without newline, then puts " There" outputs " There" with newline, so combined output is "Hi There\n".
  2. Step 2: Analyze p output

    p "!" outputs the string with quotes and newline: "\"!\"\n".
  3. Final Answer:

    Hi There "!" -> Option D
  4. Quick Check:

    print no newline + puts newline + p inspect output = C [OK]
Quick Trick: p shows quotes and newline, print no newline, puts adds newline [OK]
Common Mistakes:
  • Ignoring quotes in p output
  • Assuming print adds newline
  • Confusing puts and print behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes