Question 5
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int code = 404;
fprintf("error %d\n", code);
return 0;
}
- A %d must be %i
- B fprintf's first argument must be a FILE * stream, e.g. fprintf(stderr, "error %d\n", code) Correct
- C code must be a string
- D There is no bug
Correct Answer: Option B
Here the format string is passed as the stream and the int as the format, which the compiler rejects. Error messages usually go to stderr.
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!