reopened by
1,663 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$
reopened by

2 Answers

Best answer
5 votes
5 votes

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
Answer:

Related questions

9 votes
9 votes
2 answers
1
gatecse asked Dec 17, 2017
3,744 views
Consider the following $C$ function#include<stdio.h int main(void) { char c[]="ICRBCSIT17" char *p=c; printf("%s",c+2[p]-6[p]-1); return 0; }The output of the program is ...
2 votes
2 votes
1 answer
2
gatecse asked Dec 17, 2017
2,140 views
Consider the functionint fun(x: integer) { If x>100 then fun=x-10; else fun=fun(fun(x+11)); }For the input $x=95$, the function will return$89$$90$$91$$92$
5 votes
5 votes
1 answer
3
gatecse asked Dec 17, 2017
1,451 views
Which one of the following are essential features of object-oriented language? A.Abstraction and encapsulation B.Strictly-typed C.Type-safe property coupled with sub-type...
9 votes
9 votes
1 answer
4