ProgrammingVery hard
struct E { int n; int a[]; }; printf("%zu", sizeof(struct E)); What is printed for a struct with a flexible array member and 4-byte int?
- A. 4
- B. 0
- C. 8
- D. 1
Correct answer: A. 4
The flexible array member adds no size to sizeof. Only n is counted, so the size is 4.
More C Programming questions
- struct K { int k; }; struct K list[3] = {{3}, {1}, {2}}; int sum = 0; for (int i = 0; i < 3; i++) sum = sum 10 + list[i].k; printf("%d"…
- struct Acc { int bal; }; void add(struct Acc a, int x) { a.bal += x; } struct Acc acc = {10}; add(acc, 5); printf("%d", acc.bal); What is…
- struct Acc { int bal; }; void add(struct Acc a, int x) { a->bal += x; } struct Acc acc = {20}; add(&acc, 7); printf("%d", acc.bal); What…
- struct Node { int v; struct Node next; }; struct Node head = NULL; for (int i = 1; i <= 3; i++) { struct Node n = malloc(sizeof n); n->v =…
- struct Pair { int a; int b; }; struct Pair p = {.b = 4}; printf("%d %d", p.a, p.b); What is printed?
- struct Cfg { int depth; int width; }; struct Cfg cfg[2] = {{1, 2}, {3, 4}}; struct Cfg cp = &cfg[1]; cp->width = 10; printf("%d"…