ProgrammingHardGATE CS · Campus placements
uint32_t x = 0xFFFFFFFFu; How many times does while (x > 0) x >>= 1; execute its body, counting from the start?
- A. 32
- B. 31
- C. 33
- D. 64
Correct answer: A. 32
Each right shift removes one bit, and a value with all 32 bits set needs 32 shifts to reach 0. The loop is a standard way to count bit length.
More C Programming questions
- int cnt[3] = {0}; int p; for (p = cnt; p < cnt + 3; p++) p = p - cnt; What is the sum of cnt[0] + cnt[1] + cnt[2]?
- A loop while (!(x & 1)) { x >>= 1; c++; } counts the trailing zero bits of a nonzero uint32t x = 0b101000. What is c?
- 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?