ProgrammingHardTCS NQT · Wipro
How many inner iterations run in total? Compute with this program.
How many inner iterations run in total? Compute with this program.
#include <stdio.h>
int main(void) {
int i = 0, c = 0;
do {
for (int j = 0; j < 3; j++) {
if (j == 1) break;
c++;
}
i++;
} while (i < 2);
printf("%d", c);
}- A. 4
- B. 1
- C. 3
- D. 2
Correct answer: D. 2
Each pass through the outer loop increments c once for j = 0 and then breaks at j = 1, so the two passes give 2.
More C Programming questions
- What is the sizeof of this struct, assuming char has size 1, int has size 4 with 4-byte alignment, and a nested struct is laid out in…
- What is printed? c #include <stdio.h> long long sum(long long n, long long acc) { return n == 0 ? acc : sum(n - 1, acc + n); } int…
- How many odd multiples of 3 are there in 1 to 30? Count them with this program. c #include <stdio.h> int main(void) { int c = 0; for…
- What is printed? c #include <stdio.h> int main(void) { int m[2][2] = {{3, 1}, {4, 2}}; int s = 0; for (int i = 0; i < 2; i++) { int lo =…
- What is printed? c #include <stdio.h> int main(void) { int r0[2] = {1, 2}, r1[2] = {3, 4}; int rows[2] = {r0, r1}; int t = rows[0]…
- What is printed? The reverse of the binary digits of 13 (1101) is taken as an integer. c #include <stdio.h> int main(void) { unsigned x =…