• recategorized by
2,408 views
3 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$

2 Answers

Best answer
5 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:
Position:
Show:

Related questions

9 9 votes
2 answers 2 answers
4.7k
4.7k views
gatecse asked Dec 17, 2017
4,684 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 ...
3 3 votes
1 answers 1 answer
2.8k
2.8k views
gatecse asked Dec 17, 2017
2,843 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 5 votes
1 answers 1 answer
2.0k
2.0k views
gatecse asked Dec 17, 2017
2,013 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...
4 4 votes
2 answers 2 answers
4.5k
4.5k views
gatecse asked Dec 17, 2017
4,461 views
//Consider the program void function(int n) { int i,j,count=0; for(i=n/2;i<=n;i++) for(j=1;j<=n;j=j*2) count++; }The complexity of the program is$O(\log n)$$O(n^2)$$O(n^2...