Question 5
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int a = 2, b = 3;
int c = (a + b)++;
printf("%d\n", c);
return 0;
}
- A c must be declared first
- B ++ needs a modifiable lvalue (a variable); a + b is just a value Correct
- C Brackets cannot be used with ++
- D There is no bug; it prints 5
Correct Answer: Option B
Increment and assignment change an object, so their operand must designate one. a + b is a temporary value. Write int c = a + b + 1;.
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!