ProgrammingModerate
struct In { int v; }; struct Out { struct In in; int k; }; struct Out o = {{7}, 2}; printf("%d", o.in.v + o.k); What is printed?
- A. 7
- B. 9
- C. 2
- D. 5
Correct answer: B. 9
The inner braces {7} initialise the nested struct, so o.in.v = 7 and o.k = 2, and the sum is 9. 7 or 2 alone pick just one field, and 5 subtracts them.
More C Programming questions
- int p = NULL; if (p && p == 3) puts("match"); else puts("no match"); What is printed?
- #define MAX(a, b) ((a) > (b) ? (a) : (b)) printf("%d", MAX(3, 2 + 2)); What is printed?
- long long r = 1; for (int i = 0; i < 40; i++) r = r 2 % 1000000007; printf("%lld", r); What is printed (2^40 mod 10^9 + 7)?
- A linked list holds 10^5 nodes and must answer 10^5 queries for the k-th node. Which approach is correct and fast enough?
- An in-place sort on 10^6 ints must not use more than a few kilobytes of extra memory. Which algorithm fits?
- A quicksort with a poor pivot choice on already sorted input of n elements has what time?