Recall & Review
beginner
What does
printf do in PHP?printf formats a string and immediately prints it to the screen.
Click to reveal answer
beginner
How is
sprintf different from printf?sprintf formats a string but returns it instead of printing it. You can save or use the formatted string later.
Click to reveal answer
beginner
What does the format specifier
%d mean in printf or sprintf?%d is used to format an integer (whole number).
Click to reveal answer
intermediate
Explain the use of
%0.2f in formatting.%0.2f formats a floating-point number with 2 digits after the decimal point, adding zeros if needed.
Click to reveal answer
beginner
What happens if you use
%s in printf?%s formats a string. It inserts the string value into the formatted output.
Click to reveal answer
Which function prints the formatted string directly to the screen?
✗ Incorrect
printf formats and prints the string immediately.
What does
%f format specifier represent?✗ Incorrect
%f is used for floating-point numbers (decimals).
How do you format a number to always show 2 decimal places?
✗ Incorrect
%.2f formats a float with 2 decimal places.
Which function returns the formatted string instead of printing it?
✗ Incorrect
sprintf returns the formatted string for later use.
What will
printf("Hello %s", "World") output?✗ Incorrect
The %s is replaced by the string "World".
Describe the difference between
printf and sprintf in PHP.Think about when you want to show output immediately versus when you want to save it.
You got /3 concepts.
Explain how to format a floating-point number to 3 decimal places using
printf or sprintf.Look at the pattern for decimal precision in format specifiers.
You got /3 concepts.