What will be printed out as a result of the following code execution?

#include <iostream>

int main()
{
    int i = 3;
    int c = 0;
    while(i)
    {
        ++c;
        i ^= i & -i;
    }
    std::cout << c;
    return 0;
}
Explanation
Given code counts the number of bits set to 1 in a number.
C++
C++ Quiz
Start Quiz

or Read more about C++ Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback