ProgrammingHard
struct S { int key; int val; }; struct S arr[4] = {[2] = {7, 70}, {8, 80}}; printf("%d", arr[1].key); What is printed?
- A. 7
- B. 8
- C. 2
- D. 0
Correct answer: D. 0
Index 1 is not initialised by any designator or brace group, so it is zero.
More C Programming questions
- struct N { char name[8]; int score; }; struct N n = {"Ravi", 90}; printf("%c %d", n.name[1], n.score); What is printed?
- struct Box { int w; int h; }; struct Box boxes[2] = {{2, 3}, {4, 5}}; int area = 0; for (struct Box p = boxes; p < boxes + 2; p++) area +=…
- struct Q { int v; }; struct Q q[3] = {{5}, {1}, {3}}; struct Q lo = q; for (int i = 1; i < 3; i++) if (q[i].v < lo->v) lo = &q[i]…
- struct T { int a; double d; }; printf("%d", (int)(sizeof(struct T) == 16)); What is printed with 4-byte int and 8-byte double (natural…
- struct F { char c; double d; }; printf("%zu", sizeof(struct F)); What is printed with natural alignment and 8-byte double?
- struct G { int x; char y[3]; }; printf("%zu", sizeof(struct G)); What is printed with 4-byte int and natural alignment?