Question 3
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
#define CHARPTR char *
int main(void) {
CHARPTR first, second;
first = "alpha";
second = "beta";
printf("%s %s\n", first, second);
return 0;
}
- A String literals cannot be assigned to pointers
- B The macro makes only first a pointer; second is a char, so second = "beta" is invalid – use typedef char *CharPtr; Correct
- C printf needs %c
- D There is no bug
Correct Answer: Option B
After expansion the line is char * first, second;. Assigning a pointer to the char second is rejected. A typedef applies the pointer to every declarator.
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!