Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. Consider the function func shown below :
    int func(int num) {
    int count = 0;
        while (num) {
       count++; num>>= 1;
      }
    return (count);
    }
    The value returned by func (435) is __________.
    1. 9
    2. 17
    3. 21
    4. 27
Correct Option: A

435 ⇒ 110110011 num > > 1
Thus a num is shifted one bit right every time while loop is executed.
While loop is executed 9 times successfully, and 10th time num is zero.
&there; Count is incremented 9 times.



Your comments will be displayed only after manual approval.