Question 1
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
double side = 49;
printf("%.1f\n", sqrt(side));
return 0;
}
- A side must be an int
- B sqrt is used without its declaration – <math.h> is not included Correct
- C %.1f cannot print a double
- D There is no bug
Correct Answer: Option B
Since C99 an undeclared function cannot be called. Before that the compiler assumed it returned int, which gave garbage for double results.
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!