Question 7
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a = -1, b = -1;
int r = sscanf("12 apples", "%d %d", &a, &b);
printf("%d %d %d\n", r, a, b);
return 0;
}
- A 1 12 -1 Correct
- B 2 12 0
- C 0 -1 -1
- D 1 12 0
Correct Answer: Option A
The first %d stores 12; the second fails at "apples", so scanning stops. One item was assigned, so the result is 1 and b keeps its old value.
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!