Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



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.


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...