Question 9
Back to Exercise
What is the output of the following C program when the input is 20261111abcdef⏎?
#include <stdio.h>
int main(void) {
int a, b;
char s[4];
scanf("%2d%3d%3s", &a, &b, s);
printf("%d %d %s\n", a, b, s);
return 0;
}
- A 20 261 111 Correct
- B 2026 1111 abc
- C 20 261 abc
- D 20 26 111
Correct Answer: Option A
A width limits how many characters a conversion consumes: %2d takes "20", %3d takes "261", and %3s takes the next three non-space characters, "111".
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!