ProgrammingHardProduct company OA
What is printed?
What is printed?
struct E { char name[8]; int age; };
struct E t[] = {{"Asha", 31}, {"Bilal", 27}, {"Chen", 45}, {"Dev", 22}};
struct E *p = t, *best = t;
for (; p < t + 4; p++)
if (p->age > best->age) best = p;
printf("%s %td %c", best->name, best - t, (best - 1)->name[1]);- A. Chen 2 h
- B. Chen 3 i
- C. Chen 2 i
- D. Asha 0 s
Correct answer: C. Chen 2 i
The loop keeps a pointer to the oldest entry, Chen (45) at index 2, and best − t counts structs, not bytes. best − 1 is Bilal's entry, whose name[1] is 'i'. 'h' takes name[1] of Chen instead.
More C Programming questions
- What is printed? c int f(int a, int n) { if (n == 1) return a[0]; int m = f(a + 1, n - 1); return a[0] > m ? a[0] - m : m - a[0]; } int…
- What is printed? c printf("%.1f", 1 ? 3 : 2.5);
- What is printed? c int a = 0, b = 10; while (a < b) { a += 3; b -= 2; } printf("%d %d", a, b);
- After int q = realloc(p, 2 n sizeof q); succeeds (q is not NULL), where p pointed to n ints, which statement is true?
- With int i = 1, x; int a[5] = {0}; which of these statements have undefined behaviour? (i) i = i++ + 1; (ii) a[i] = i++; (iii) i = (i, i +…
- Which of the objects A to E have static storage duration (they live for the whole run of the program, in the data or BSS segment)? c int…