Question 7
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
double d = 0.0001;
if (d)
puts("double is true");
int n = (int) d;
if (!n)
puts("int is false");
return 0;
}
- A double is true int is false Correct
- B double is true
- C int is false
- D Nothing
Correct Answer: Option A
As a condition, 0.0001 is compared with 0.0 – not equal, so true. Converting to int truncates it to 0, which is false. The type at the moment of the test matters.
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!