Question 7
Back to Exercise
What is the output of the following C program?
#include <math.h>
#include <stdio.h>
int main(void) {
double inf = INFINITY;
printf("%f %f %d\n", inf + 1, -inf * 2, isnan(inf - inf) != 0);
return 0;
}
- A inf -inf 1 Correct
- B inf -inf 0
- C inf inf 1
- D nan nan 1
Correct Answer: Option A
Infinity absorbs finite values and keeps its sign through multiplication. But ∞ − ∞ has no meaningful answer, so it gives NaN.
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!