Question 3
Back to Exercise
What is the output of the following C program?
#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!