Question 7
Back to Exercise
The program below has a problem. Which statement correctly describes it?
#include <stdio.h>
struct packet {
char data[];
int length;
};
int main(void) {
printf("%zu\n", sizeof(struct packet));
return 0;
}
- A data[] must have a size
- B A flexible array member must be the last member of the struct Correct
- C length must be unsigned
- D There is no error
Correct Answer: Option B
The flexible array extends past the end of the struct, so nothing can follow it. Move it last: struct packet { int length; char data[]; };.
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!