Question 1
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
typedef struct {
int value;
Node *next;
} Node;
int main(void) {
Node n = {1, NULL};
printf("%d\n", n.value);
return 0;
}
- A NULL cannot initialise a pointer member
- B Node does not exist until the end of the typedef; give the struct a tag and write struct node *next Correct
- C value must come after next
- D There is no bug
Correct Answer: Option B
The alias is introduced only after the closing brace. Write typedef struct node { int value; struct node *next; } Node;, or declare typedef struct node Node; before the struct definition.
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!