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));
}
  1. A. 6 32
  2. B. 5 31
  3. C. 6 31
  4. 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

Exams that ask this topic