ProgrammingHardProduct company OA
What is printed?
What is printed?
struct In { int a[2]; };
struct Out { struct In in[2]; int k; } o = {{{{1, 2}}, {{3, 4}}}, 5};
printf("%d %d", o.in[1].a[0], o.in[0].a[1] + o.k);- A. 3 6
- B. 2 7
- C. 1 7
- D. 3 7
Correct answer: D. 3 7
The braces follow the nesting: the outer struct, then the array in, then each struct In, then each array a. So in[0].a = {1, 2}, in[1].a = {3, 4} and k = 5. in[1].a[0] = 3 and 2 + 5 = 7.
More C Programming questions
- What is printed? c struct In { int a[2]; }; struct Out { struct In in[2]; int k; } q = {1, 2, 3, 4, 5}; printf("%d %d", q.in[1].a[1], q.k);
- What is printed? c int c = 0; int f(int n) { c++; return n <= 1 ? 1 : f(n / 2) + f(n - n / 2); } int main(void) { int r = f(7); printf("%d…
- Which of these loops run their body exactly for i = 4, 3, 2, 1, 0 (once each) with an unsigned i? c for (unsigned i = 5; i-- > 0; ) { /…
- What is printed? c int x = -1; unsigned y = 1; printf("%d", (x < 0 ? x : y) < 0);
- What is printed? c int a[] = {1, 2, 3, 4, 5, 6}; int s = 0; for (int p = a; p < a + 6; p += 2) s += p p[1]; printf("%d", s);
- What is printed? c int cat(int n) { if (n <= 1) return 1; int s = 0; for (int i = 0; i < n; i++) s += cat(i) cat(n - 1 - i); return s; }…