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:
s1 = "test";
s2 = "test";
if strncmp(s1, s2)
disp('Equal');
end
Adisp should be replaced with fprintf
BStrings must be converted to char arrays
Cstrncmp requires a third argument for number of characters
Dif statement syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check strncmp function usage

    strncmp requires three inputs: two strings and number of characters to compare.
  2. Step 2: Identify missing argument

    The code calls strncmp(s1, s2) missing the third argument, causing an error.
  3. Final Answer:

    strncmp requires a third argument for number of characters -> Option C
  4. Quick Check:

    strncmp needs length argument [OK]
Quick Trick: Always provide length argument to strncmp [OK]
Common Mistakes:
  • Omitting length argument
  • Confusing strncmp with strcmp
  • Thinking disp needs change

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes