ProgrammingModerate
struct S { int id; int v; }; struct S a[4] = {{1,9},{2,8},{3,7},{4,6}}; struct S b[4]; memcpy(b, a, sizeof a); b[0].v = 0; printf("%d %d", a[0].v, b[0].v); What is printed?
- A. 0 0
- B. 0 9
- C. 9 0
- D. 9 9
Correct answer: C. 9 0
memcpy copies the whole block, so b is independent of a. Changing b[0].v does not affect a[0].v.
More C Programming questions
- struct Grid { int cell[2][2]; }; struct Grid g1 = {{{1, 2}, {3, 4}}}; struct Grid g2 = g1; g2.cell[1][1] = 0; printf("%d", g1.cell[1][1])…
- Which is the correct way to count distinct keys in a sorted struct array a[0..n-1] (n >= 1) by key?
- A sorted array of records is searched for the first record whose key is at least x (a lower bound). Which loop is correct?
- An array of 2 x 10^5 records must be answered with 2 x 10^5 queries, each asking how many records have key <= q. Which approach is correct…
- After removing duplicate keys from a sorted array of records with the two-index method (keep a[w] when its key differs from the last kept…
- Bubble sort on the records of 4 keys {4, 3, 2, 1} with a swap count: how many swaps are made?