Bird
0
0

Identify the error in this MATLAB code:

medium📝 Debug Q6 of 15
MATLAB - String Handling
Identify the error in this MATLAB code:
str = 'Hello';
len = strlength(str);
ANo error; code runs correctly
BMissing semicolon after strlength
Cstr should be defined with double quotes
Dstrlength cannot be used on character arrays
Step-by-Step Solution
Solution:
  1. Step 1: Check function compatibility

    The function strlength works only on string data type, not on character arrays.
  2. Step 2: Identify data type of str

    Since str is defined with single quotes, it is a character array, so strlength causes an error.
  3. Final Answer:

    strlength cannot be used on character arrays -> Option D
  4. Quick Check:

    strlength needs string, not char array [OK]
Quick Trick: Use strlength only on strings, not char arrays [OK]
Common Mistakes:
  • Assuming strlength works on char arrays
  • Ignoring data type of variable
  • Thinking semicolon causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes