-
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 __________.
-
- 9
- 17
- 21
- 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.