ProgrammingModerateCompetitive coding (CP)
What is printed?
What is printed?
#include <stdint.h>
#include <stdio.h>
int tz(uint32_t x) {
int n = 0;
while (!(x & 1u)) {
x >>= 1;
n++;
}
return n;
}
int main(void) {
printf("%d %d", tz(0x6C0u), tz(0x80000000u));
}- A. 6 32
- B. 5 31
- C. 6 31
- D. 6 0
Correct answer: C. 6 31
0x6C0 = 1728 = 2^6 * 27, so six trailing zeros. The value 0x80000000 has its only set bit at position 31.
More C Programming questions
- Assume int is 32 bits with limits INTMIN = -2147483648 and INTMAX = 2147483647. What is printed? c #include <limits.h> #include <stdio.h>…
- int n = 8, c = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j = 2) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 100; i = 3) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 100; i >= 1; i /= 2) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 1; i <= 100; i++) for (int j = 1; j <= i; j++) c++; printf("%d", c); What is printed?
- int c = 0; for (int i = 0; i i <= 50; i++) c++; printf("%d", c); What is printed?