ProgrammingHardAccenture · Product company OA
What is printed?
What is printed?
int i = 0, s = 0;
do {
if (++i == 3) continue;
if (i == 5) break;
s += i;
} while (i < 10);
printf("%d %d", s, i);- A. 7 5
- B. 15 10
- C. 10 5
- D. 7 4
Correct answer: A. 7 5
i = 1 and 2 are added (s = 3). At i = 3, continue jumps to the while test, which passes, so nothing is added. i = 4 is added (s = 7), and at i = 5 the loop breaks before adding.
More C Programming questions
- What is printed? c struct N { int v; struct N nx; }; void del(struct N h, int x) { while (h) { if ((h)->v == x) h = (h)->nx; else h =…
- What is printed? c int rot(const char a, const char b) { char buf[32]; if (strlen(a) != strlen(b)) return 0; strcpy(buf, a); strcat(buf…
- What is printed? c int alt(unsigned x) { unsigned y = x ^ (x >> 1); return (y & (y + 1)) == 0; } int main(void) { printf("%d%d%d", alt(5)…
- What is printed? c struct In { int a[2]; }; struct Out { struct In in[2]; int k; } o = {{{{1, 2}}, {{3, 4}}}, 5}; printf("%d %d"…
- 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…