Bird
0
0

Find the error in this MATLAB code:

medium📝 Debug Q7 of 15
MATLAB - String Handling
Find the error in this MATLAB code:
str = 'apple orange apple';
newStr = strrep(str, apple, 'banana');
disp(newStr);
AMissing semicolon after strrep
Bstrrep cannot replace repeated words
Cdisp cannot display strings
Dapple should be in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check argument types in strrep

    All string arguments must be enclosed in quotes.
  2. Step 2: Identify missing quotes

    apple is used without quotes, causing an error.
  3. Final Answer:

    apple should be in quotes -> Option D
  4. Quick Check:

    String literals need quotes = apple should be in quotes [OK]
Quick Trick: Always quote string literals in strrep arguments [OK]
Common Mistakes:
  • Forgetting quotes around strings
  • Assuming variables without quotes are strings
  • Misusing disp function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes