Question 1
Back to Exercise
The program below has a problem. Which statement correctly describes it?
#include <stdio.h>
struct node {
int value;
struct node next;
};
int main(void) {
printf("%zu\n", sizeof(struct node));
return 0;
}
- A value must come after next
- B struct node next; – a struct cannot contain itself; use struct node *next; Correct
- C sizeof cannot be used on a struct
- D There is no error
Correct Answer: Option B
While its definition is still open, struct node is an incomplete type with unknown size, so it cannot be a member. A pointer to it has a known size: struct node *next;.
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!