ProgrammingHard
struct Item { int id; int qty; }; struct Item a[2] = {{1, 5}, {2, 7}}; struct Item b = a[1]; b.qty = 0; printf("%d %d", a[1].qty, b.qty); What is printed?
- A. 7 0
- B. 0 0
- C. 7 7
- D. 0 7
Correct answer: A. 7 0
Assigning a struct copies it, so changing b does not change a[1]. a keeps 7 and b has 0.
More C Programming questions
- struct Item { int id; int qty; }; struct Item a[3] = {{1, 2}, {3, 4}}; printf("%d", a[2].qty); What is printed?
- struct S { int key; int val; }; struct S arr[4] = {[2] = {7, 70}, {8, 80}}; printf("%d", arr[3].val); What is printed?
- struct S { int key; int val; }; struct S arr[4] = {[2] = {7, 70}, {8, 80}}; printf("%d", arr[1].key); What is printed?
- 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]…