ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int i = 0, n = 0;
while (i++, i < 5)
n++;
printf("%d", n);
}- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
The comma operator evaluates i++ and then tests i < 5. The body runs for i = 1 to 4, so n = 4.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int i = 0, c = 0; do { i++; if (i % 2) continue; c++; } while (i < 6); printf("%d"…
- 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"…