ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int i = 5;
do {
i++;
} while (i < 3);
printf("%d", i);
}- A. 5
- B. 6
- C. Nothing: the loop never ends
- D. 7
Correct answer: B. 6
A do-while runs its body before the first test, so i becomes 6; then 6 < 3 is false and the loop exits. 5 treats it as a while loop, 7 runs the body twice, and the infinite-loop answer confuses do-while with repeat-until.
More C Programming questions
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%d %zu", 1 ? 'A' : 0, sizeof(1 ? 'A' : 0)); }
- What is printed? Assume unsigned long long is 64 bits. c #include <stdio.h> int main(void) { unsigned long long x = (1ULL << 40) - 1; int…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3}; int p = a; p += 2; printf("%d", p - (p - 2)); }
- What is printed? Assume unsigned short is 16 bits and int is 32 bits. c #include <stdio.h> int main(void) { printf("%d", (unsigned…
- How many binary strings of length 4 contain no two consecutive 1s? Compute with this recursive program. c #include <stdio.h> int f(int n)…
- What is printed? c #include <stdio.h> int main(void) { unsigned char a = 100, b = 200; unsigned char s = (unsigned char)(a + b) / 2…