LearnFrenzy
Sign in Take a free test

C Input / Output · Predict the Output · Question 3

Width taken from an argument with %*d – output Answer, explanation & discussion

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

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    printf("[%*d][%-*d][%.*f]\n", 5, 42, 4, 7, 2, 2.71828);
    return 0;
}
  • A [ 42][7 ][2.72] Correct
  • B [42 ][ 7][2.72]
  • C [5 42][4 7][2 2.71828]
  • D [ 42][7 ][2.71]
Correct Answer: Option A

Each * consumes an int argument first: width 5 for 42, width 4 (left-aligned) for 7, precision 2 for 2.71828, which rounds to 2.72.

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