Bird
0
0

Which of the following is the correct syntax to print a string variable str in C?

easy📝 Syntax Q3 of 15
C - Input and Output
Which of the following is the correct syntax to print a string variable str in C?
Aprintf("%s", str);
Bprintf("%c", str);
Cprintf("%d", str);
Dprintf("%f", str);
Step-by-Step Solution
Solution:
  1. Step 1: Identify the format specifier for strings

    The correct format specifier for strings is %s.
  2. Step 2: Match the specifier with the variable type

    %c is for characters, %d for integers, and %f for floats, so they are incorrect for strings.
  3. Final Answer:

    printf("%s", str); -> Option A
  4. Quick Check:

    String output = %s [OK]
Quick Trick: Use %s to print strings in printf [OK]
Common Mistakes:
  • Using %c for strings
  • Using %d for strings
  • Using %f for strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes