Consider the following C++ function f(): unsigned int f(unsigned int n) {…

UGC NET 2019

Consider the following C++ function f():

unsigned int f(unsigned int n) {

unsigned int b=0;

while (n) {

b+=n & 1;

n>>1;

}

return b;

}

The function f() returns the int that represents the ____P____ in the binary representation of positive integer n, where P is

  1. A.

    number of 0’s

  2. B.

    number of bits

  3. C.

    number of consecutive 1’s

  4. D.

    number of 1’s

Attempted by 16 students.

Sign up free to check your answer

Sign up free

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs

Loading lesson…