ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
const char *s = " a bb ccc ";
int words = 0, in = 0;
for (; *s; s++) {
if (*s == ' ') in = 0;
else if (!in) { in = 1; words++; }
}
printf("%d", words);
}- A. 4
- B. 3
- C. 2
- D. 6
Correct answer: B. 3
The state flag in marks being inside a word, so only the first letter of each run increments the count. The three words are a, bb and ccc.
More C Programming questions
- What is printed? c #include <stdio.h> int ways(int n) { if (n == 0) return 1; if (n < 0) return 0; return ways(n - 1) + ways(n - 3); } int…
- What is printed? c #include <stdint.h> #include <stdio.h> uint64t pw(uint64t b, uint64t e, uint64t m) { uint64t r = 1; b %= m; while (e) {…
- What is printed? c #include <stdio.h> int main(void) { unsigned char comp[51] = {0}; int count = 0; for (int i = 2; i <= 50; i++) { if…
- What is printed? c #include <stdio.h> int main(void) { int s = 0; for (int i = 0; i < 10; i++) { if (i % 3 == 0) continue; if (i > 7)…
- What is printed? c #include <stdio.h> int main(void) { printf("%d %d", sizeof(char) < -1, -1 < 0); }
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint32t a = 0xFFFFFFFDu, b = 5u, c = 4u, d = 0xFFFFFFFFu, e =…