ProgrammingHardAccenture · Product company OA
What is printed?
What is printed?
int i, c = 0;
for (i = 0; i < 10; i += i + 1) c++;
printf("%d %d", c, i);- A. 4 15
- B. 3 15
- C. 5 15
- D. 4 7
Correct answer: A. 4 15
The update makes i = 2i + 1: 0, 1, 3, 7 run the body (4 passes), then i becomes 15 and the test fails. '4 7' reports the last value used inside the loop, not the final value.
More C Programming questions
- What is printed? c int a = 2, b = 4; printf("%d %d %d", a & b, a && b, a | b);
- What is printed? c int z(int n) { return n < 5 ? 0 : n / 5 + z(n / 5); } int main(void) { printf("%d %d", z(100), z(125)); }
- What is printed? c int next(void) { static int n; return n += 2; } int prev(void) { static int n = 10; return n -= 3; } int main(void) {…
- What is printed? c void rev(char a, char b) { while (a < b) { char t = a; a++ = b; b-- = t; } } int main(void) { char s[] = "abc de"…
- What is printed? c int n = 0; int t(void) { n++; return 1; } int f(void) { n++; return 0; } int main(void) { int r = f() || t() && f() ||…
- What is printed? c int a[] = {3, 5, 0, 7}, i = 0, s = 0, v; while ((v = a[i++])) s += v; printf("%d %d", s, i);