ProgrammingHard
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]); What is printed?
- A. 0
- B. 3
- C. 2
- D. 4
Correct answer: D. 4
Assignment of a struct copies all its members, including arrays inside it. Only the copy g2 changes.
More C Programming questions
- 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?
- A struct array holds records with an int key; the program calls qsort with the comparator (int)(a->key - b->key) for keys near INTMAX and…