All mock tests are FREE till 31 December — register to save your progress

Consider the following function ) : f n unsigned int (unsigned int )( b = 0

unsigned int ;
while (n) {
b+ = n&1
;
n ≫>= 1
;
}
return b;}
```
f (

The function ) returns the int that represents _P_ the in the binary representation of positive n P

integer , where is

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. number of 1's

Explanation

b += n & 1; n >>= 1 adds each low bit and shifts: it counts the 1 bits.

More Programming Languages and Computer Graphics questions