Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - Output and String Handling
What will be the output of the following PHP code?
$num = 42;
printf("%05d", $num);
A 42
B00042
C43
D41
Step-by-Step Solution
Solution:
  1. Step 1: Understand the %05d format

    %05d means print an integer padded with zeros to width 5.
  2. Step 2: Apply padding to the number 42

    42 is two digits, so pad with three zeros in front: 00042.
  3. Final Answer:

    00042 -> Option B
  4. Quick Check:

    %05d pads integer with zeros to width 5 [OK]
Quick Trick: Use %0nd to pad integers with zeros to width n [OK]
Common Mistakes:
  • Confusing zero padding with space padding
  • Ignoring width specifier
  • Using %d without width

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes