ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
int c = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
if (j == 1) break;
c++;
}
printf("%d", c);- A. 6
- B. 9
- C. 1
- D. 3
Correct answer: D. 3
break leaves only the innermost loop. Each outer pass counts j = 0 once and breaks at j = 1, so c = 3. '1' assumes break ends both loops.
More C Programming questions
- With 4-byte int, what is printed? c int a[4] = {1, 2, 3, 4}; char c = (char )a; int p = (int )(c + 8); printf("%d %td", p, p - a);
- What does Staticassert(sizeof(long) >= 8, "need 64-bit long"); do in C11?
- What is printed? c int i = 0, s = 0; do { if (++i == 3) continue; if (i == 5) break; s += i; } while (i < 10); printf("%d %d", s, i);
- 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)…