ProgrammingHardGATE CS · Campus placements
A loop while (!(x & 1)) { x >>= 1; c++; } counts the trailing zero bits of a nonzero uint32_t x = 0b101000. What is c?
- A. 2
- B. 5
- C. 3
- D. 1
Correct answer: C. 3
The loop shifts out the low zero bits until bit 0 is set. In 101000 there are three trailing zeros, so c is 3. The loop never ends for x = 0, so the input must be nonzero.
More C Programming questions
- uint64t mask = (1ULL << 40) - 1; What is mask?
- int a[] = {3, 1, 2}; qsort(a, 3, sizeof(int), cmp) sorts ascending, where cmp compares with (x > y) - (x < y). Then What is a[0]100 +…
- A program must answer 10^5 range-sum queries on an array of 10^5 ints within a 1 second limit. Which approach is fast enough?
- Using fast exponentiation with reduction modulo 1000000007 after each multiplication, what is 2^100 mod 1000000007?
- int n = -1; uint64t u = (uint64t)n; What is u?
- uint32t fib(int n) iteratively computes a = 0, b = 1, then n times: t = a + b; a = b; b = t, with all arithmetic in uint32t. What is…