Aspire Faculty ID #13670 · Topic: JAMIA MILLIA ISLAMIA MCA 2023 · Just now
JAMIA MILLIA ISLAMIA MCA 2023

Give output of following C code:

int count(unsigned x)
{
    int b;
    for (b = 0; x != 0; x >>= 1)
        if (x & 1)
            b++;
    return b;
}

int main()
{
    unsigned int a = 3;
    printf("%d", count(a));
    return 0;
}

Solution

```ruby Solution: The function `count()` counts number of 1-bits in the binary representation of `x`. For `a = 3` Binary of 3 = `11` → Number of 1 bits = 2 Hence output = 2.

Previous 10 Questions — JAMIA MILLIA ISLAMIA MCA 2023

Nearest first

Next 10 Questions — JAMIA MILLIA ISLAMIA MCA 2023

Ascending by ID
Ask Your Question or Put Your Review.

loading...