in Programming in C reopened by
1,643 views
3 votes
3 votes

Consider the function

int func(int num)
{
    int count=0;
    while(num)
    {
        count++;
        num>>=1;
    }
    return(count);
}

For $func(435)$ the value returned is

  1. $9$
  2. $8$
  3. $0$
  4. $10$
in Programming in C reopened by
by
1.6k views

2 Comments

9 no of bit to represent 435
0
0
reshown by
0
0

2 Answers

5 votes
5 votes
Best answer

num>>1 is equivalent to num/2

in while loop , value of num will change as follows:

  1.  435 /2 =217  
  2.  217 /2 =108  
  3.  108 /2 =54 
  4.  54 /2 =27
  5.  27 /2 =13 
  6. 13 /2 =6 
  7. 6 /2 =3
  8. 3 /2 =1
  9. 1 /2 =0 

Since it looped 9 times value of count will be 9

Answer is A

selected by
by
–1 vote
–1 vote
Answer:

Related questions