Consider the following C functions.
|
|
The value returned by is _______.
GATE CSE 2020Algorithms › Program & Function TracingVerified
Consider the following C functions.
|
|
The value returned by is _______.
81
Trace the two functions with a = 3 and b = 4. First, tob(4, arr) fills arr with the binary bits of 4 from least significant bit to most significant bit and returns the number of bits. Then pp(3,4) iterates over those bits; whenever arr[i] is 1, it multiplies tot by ex, and it squares ex after every iteration.
The binary bits of 4 are stored as arr = [0,0,1] in LSB-first order, and the only set bit is at position 2. Since ex is squared after each iteration, it equals $3^(2^2) = 3^4 = 81$ at that position, so tot becomes 81.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.