Bird
0
0

What does the %s format specifier do in printf or sprintf in PHP?

easy📝 Conceptual Q11 of 15
PHP - Output and String Handling
What does the %s format specifier do in printf or sprintf in PHP?
AIt formats the variable as a string.
BIt formats the variable as an integer.
CIt formats the variable as a floating-point number.
DIt formats the variable as a boolean.
Step-by-Step Solution
Solution:
  1. Step 1: Understand format specifiers

    The %s specifier is used to insert a string value into the formatted output.
  2. Step 2: Match specifier to variable type

    Since %s is for strings, it converts the variable to a string representation.
  3. Final Answer:

    It formats the variable as a string. -> Option A
  4. Quick Check:

    %s = string [OK]
Quick Trick: Remember %s means string, %d integer, %f float [OK]
Common Mistakes:
  • Confusing %s with %d or %f
  • Using %s for numbers without converting
  • Thinking %s formats booleans

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes