54 views

what does putchar(x&m) does in the question?

edited | 54 views
0
0
I think option A is correct.
0
yes..how?
+1
n = n & (n-1) // will give 136.

Let's come to the inside the Display function.

Here loop is running from the 31 to 0.

For the first time i = 31.

then m = 2^31.

Perform bitwise & between ( 136 & 2^31) if it is not equal to zero then print 1 otherwise 0.

here will be zero So, it will print 0.

Here 136 = 1000 1000

Then for the loop i = 7.

m = 2^7 = 128.

( 136 & 128) here result will be 0.

you can further proceed.

00000000 00000000 00000000 10001000
+1
Let me explain you!!

In main if we apply bitwise & between n and n-1 we will get the value of n as 136 i.e. 10001000.

And new value of n is being passed to display.

In display:

m=1<<i ------ this statement is left shift of 1 by i bits,

so for i = 31 ,

m= 10000000000000000000000000000000

for i = 20

m=1000000000000000000000000000000

...

...

and the statement is getting repeated 32 times

and each time x&m is to calculated.

and by ternary operator either we get 1 or 0...

That's how the answer is A..

Hope this helps!!