Bird
0
0

What will be the output of this MATLAB code?

medium📝 Predict Output Q5 of 15
MATLAB - String Handling
What will be the output of this MATLAB code?
str = sprintf('Hex: %X', 255); disp(str);
AHex: 0xFF
BHex: ff
CHex: FF
DHex: 255
Step-by-Step Solution
Solution:
  1. Step 1: Understand %X format specifier

    %X formats an integer as uppercase hexadecimal.
  2. Step 2: Convert 255 to hexadecimal

    255 in hex is FF (uppercase).
  3. Final Answer:

    Hex: FF -> Option C
  4. Quick Check:

    %X outputs uppercase hex = FF for 255 [OK]
Quick Trick: Use %X for uppercase hex, %x for lowercase hex [OK]
Common Mistakes:
  • Using lowercase hex with %X
  • Expecting decimal output
  • Adding 0x prefix automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes