ProgrammingModerateGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned s = 0;
for (unsigned b = 1; b; b <<= 1)
s += 1;
printf("%u", s);
}- A. 31
- B. 32
- C. 33
- D. 64
Correct answer: B. 32
b takes the 32 values 1, 2, 4, ..., 2^31, and the next shift wraps it to 0, so the loop body runs 32 times.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (3 & 1) == 1 ? 'y' : 'n'); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (7 & 5) | (2 ^ 6) << 1); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 5 > 3 ? 2 > 1 ? 7 : 8 : 9); }
- What is printed? c #include <stdlib.h> #include <stdio.h> int cmp(const void a, const void b) { int x = (const int )a, y = (const int )b…
- What is printed? c #include <stdio.h> unsigned fib(unsigned n) { unsigned a = 0, b = 1; for (unsigned i = 0; i < n; i++) { unsigned t = a…
- What is printed? c #include <stdio.h> void rev(const char s) { if (s == '0') return; rev(s + 1); putchar(s); } int main(void) {…