ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int i = 0, c = 0;
do {
i++;
if (i % 2) continue;
c++;
} while (i < 6);
printf("%d", c);
}- A. 2
- B. 4
- C. 6
- D. 3
Correct answer: D. 3
continue in a do-while jumps to the condition test, so the odd values of i skip the increment. The even values 2, 4 and 6 are counted, giving 3.
More C Programming questions
- After sorting by squared distance from the origin, with ties broken by x ascending, what is printed? c #include <stdio.h> #include…
- How many integers x in 1..255 have exactly four set bits? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xDEAD; int c = 0; unsigned t = x & 0xAAAA; while (t) { c += t & 1u; t…
- How many comparisons does bsearch-style binary search make to find the key 6 in the sorted array 0 to 9? Compute with the program. c…
- What is printed? c #include <stdio.h> int main(void) { int s = 0; for (unsigned i = 0; i < 8; i++) s += (i ^ (i >> 1)) & 1u; printf("%d"…
- What is printed? Assume int is 32 bits. c #include <stdio.h> int main(void) { int a = -3; unsigned b = 2; printf("%u", a b); }