Question 1
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int x = 0;
if (x = 5)
printf("yes %d\n", x);
else
printf("no %d\n", x);
return 0;
}
- A yes 5 Correct
- B no 0
- C no 5
- D yes 0
Correct Answer: Option A
x = 5 stores 5 in x and evaluates to 5, which is true. The comparison x == 5 was probably intended – compilers warn about this line.
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!