Question 2
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int a = 5, b = -1;
if (a > 0)
if (b > 0)
printf("A\n");
else
printf("B\n");
printf("done\n");
return 0;
}
- A B done Correct
- B done
- C A done
- D A B done
Correct Answer: Option A
Despite the indentation, the else belongs to if (b > 0). a > 0 is true and b > 0 is false, so the inner else prints B.
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!