Bird
0
0

Find the mistake in this MATLAB code:

medium📝 Debug Q7 of 15
MATLAB - String Handling
Find the mistake in this MATLAB code:
str1 = 'Data';
str2 = 'Science';
result = strcat(str1, ' ', str2);
disp(result);
Astrcat does not add spaces automatically
BUsing space as separate argument causes error
Cstrcat removes trailing spaces, so space is lost
DNo mistake, code works correctly
Step-by-Step Solution
Solution:
  1. Step 1: Understand strcat behavior with spaces

    strcat removes trailing spaces from inputs, so the space argument is removed.
  2. Step 2: Predict output

    The output will be 'DataScience' without space between words.
  3. Final Answer:

    strcat removes trailing spaces, so space is lost -> Option C
  4. Quick Check:

    strcat trims spaces, losing intended spaces [OK]
Quick Trick: Use square brackets [] to keep spaces when concatenating [OK]
Common Mistakes:
  • Expecting strcat to keep spaces
  • Using strcat with separate space argument
  • Not knowing strcat trims spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes