ProgrammingHardProduct company OA
What is printed?
What is printed?
struct N { int v, next; } t[] = {{10, 2}, {20, -1}, {30, 4}, {40, 1}, {50, 1}};
int s = 0;
for (int i = 0; i != -1; i = t[i].next) s += t[i].v;
printf("%d", s);- A. 90
- B. 110
- C. 150
- D. 60
Correct answer: B. 110
The next fields form a linked list stored in an array: 0 → 2 → 4 → 1 → end. That visits 10 + 30 + 50 + 20 = 110. Node 3 (40) is never reached because nothing links to it; '150' sums the whole array.
More C Programming questions
- Given int x; const int pc; int p; int const cp = &x;, which assignment is a constraint violation that the compiler must diagnose?
- What is printed? c #define S(x) #x printf("%zu %zu", strlen(S("hi")), sizeof(S(ab)));
- What is printed? c int paths(int r, int c) { return (r == 0 || c == 0) ? 1 : paths(r - 1, c) + paths(r, c - 1); } int main(void) {…
- Assume 8-bit unsigned char. What is printed? c int n = 0; for (unsigned char c = 0; c < 300; c++) { n++; if (n > 1000) break; }…
- Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed? c int big = 16777217; / 2^24 + 1 / float f = big; printf("%d"…
- Assume 8-bit unsigned char. What is printed? c int i; unsigned char c; double d; d = c = i = 300 + 0.7; printf("%d %d %.1f", i, c, d);