Question 2
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
#define START 1
#define RESUME 1
int main(void) {
int code = 1;
switch (code) {
case START: puts("start"); break;
case RESUME: puts("resume"); break;
}
return 0;
}
- A Macros cannot be case labels
- B START and RESUME both expand to 1, and two case labels may not have the same value Correct
- C code must be a char
- D There is no bug
Correct Answer: Option B
After preprocessing both labels are case 1:, a duplicate, which is a compile error. Give the constants distinct values – an enum does that automatically.
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!