bool get (int n)
{
int x = 0;
while( n )
{
x += n&1;
n = n>>1;
}
return x;
}
When I solved, I figured this function should return total no of set bits of n
bool get (int n)
{
int x = 0;
while( n )
{
x += n&1;
n = n>>1;
}
return x;
}
When I solved, I figured this function should return total no of set bits of n
Yes, you are correct what is your doubt??
when i run it on ide, it gives a different answer
Hi,
Since, return type is bool if the number has atleast one set bit it will return true so 1 is printed in output else return false, so 0 is printed in output.
ohhh okay thanks a lot 
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.