ProgrammingHardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x = 7;
int i = 0;
while (x & 1u) { x >>= 1; i++; }
printf("%d", i);
}- A. 2
- B. 4
- C. 3
- D. 0
Correct answer: C. 3
The loop counts the low bits that are set. 7 = 111 has three of them before the first zero, which is above bit 2.
More C Programming questions
- What is printed? Assume unsigned short is 16 bits. c #include <stdio.h> int main(void) { unsigned short a = 255, b = 255; unsigned c = a…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char w[] = {"ab", "cde"}; char p = w; printf("%d"…
- What is printed? c #include <stdio.h> int main(void) { int a[5] = {0}; int p = a + 4; printf("%ld", (long)(p - &a[0])); }
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 3, 2, 5}, c = 0; for (int p = a; p < a + 4; p++) if (p > 2) c++…
- What is printed? c #include <stdio.h> int main(void) { int x = 0, p = &x; p++ = 5; printf("%d", x); }
- What is printed? c #include <stdio.h> int main(void) { const char s = "abc"; printf("%d", s[3] == '0'); }