GATE Computer ScienceHardGATE CSE · TCS
int count(unsigned x) { int c = 0; while (x) { x &= (x - 1); c++; } return c; } What is the value of count(0xB5D)?
- A. 7
- B. 9
- C. 10
- D. 8
Correct answer: D. 8
Each iteration clears the lowest set bit, so the result is the number of 1-bits in 0xB5D = 1011 0101 1101, which is 8.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int a[3][4] holds a[i][j] = 4i + j (row-major, sizeof(int) = 4). What does printf("%d %d", (a[2] - 3), (a + 1) + (a + 5)); print?
- A max-heap is stored in the array [90, 70, 80, 40, 50, 60, 75, 20, 10] (index 0 is the root). After one delete-max operation (the last…
- To find both the largest and the second-largest among 16 distinct numbers, a knockout tournament is played and then the second-largest is…
- Twelve keys 15, 22, 5, 31, 10, 27, 12, 40, 3, 18, 20, 25 are inserted in this order into a hash table of 5 slots with separate chaining…
- Keys 40, 20, 60, 10, 30, 50, 70, 25, 35, 45, 65 are inserted into an empty BST. The root 40 is then deleted, replacing it by its inorder…
- Integers 1, 2, 3, 4, 5, 6 are pushed onto a stack in this order, with pops allowed at any time. How many distinct complete output…