ProgrammingVery hardGATE CS · Competitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int c = 0;
for (unsigned x = 0; x < 256; x++)
if ((x & (x >> 1)) == 0) c++;
printf("%d", c);
}- A. 55
- B. 89
- C. 34
- D. 56
Correct answer: A. 55
Counting 8-bit strings with no two adjacent set bits gives the Fibonacci number F(10) = 55. Using F(9) = 34 or the next value 89 are the usual off-by-one slips.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { const char s[] = {"ab", "cde", "f"}; printf("%c%c", s[2], s[1][2]); }
- What is printed? c #include <stdio.h> int main(void) { unsigned x[] = {4000000000u, 4000000000u, 4000000000u}; unsigned s = 0; for (int i…
- What is printed? c #include <stdio.h> int main(void) { int c = 0; for (int i = 0, j = 10; i < j; i += 2, j--) c++; printf("%d", c); }
- char b[5]; int n = snprintf(b, sizeof b, "%s", "abcdefgh"); printf("%s %d", b, n); What is printed?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); printf("%d %s", n, buf); What is printed?
- char s[8] = "ab"; strncat(s, "cdefgh", 2); printf("%zu", strlen(s)); What is printed?