Question 8
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int x = 3, y = 4;
int* p, q;
p = &x;
q = &y;
printf("%d %d\n", *p, *q);
return 0;
}
- A x and y must be pointers
- B Only p is a pointer; q is an int, so q = &y and *q are invalid Correct
- C p must be initialised in its declaration
- D There is no bug
Correct Answer: Option B
Each declarator needs its own *: int *p, *q; – or, clearer, one declaration per 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!