LearnFrenzy
Sign in Take a free test

C Input / Output · Predict the Output · Question 4

Precision on %s: %.3s and %8.3s – output Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    const char *s = "LearnFrenzy";
    printf("[%.3s][%8.3s][%-8.5s][%2s]\n", s, s, s, "C");
    return 0;
}
  • A [Lea][ Lea][Learn ][ C] Correct
  • B [Lea][Lea ][ Learn][C ]
  • C [LearnFrenzy][ Lea][Learn ][ C]
  • D [Lea][ Lea][Learn ][C]
Correct Answer: Option A

For strings, precision is the maximum number of characters printed and width the minimum field size: "Lea", then "Lea" right-aligned in 8, "Learn" left-aligned in 8, and "C" padded to 2.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links