C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 11)
11.
What will be the output of the program?
#include<stdio.h>

int main()
{
    unsigned int res;
    res = (64 >>(2+1-2)) & (~(1<<2));
    printf("%d\n", res);
    return 0;
}
32
64
0
128
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
24 comments Page 3 of 3.

Ashu bhosale said:   1 decade ago
@Rakshith.

Answer is z=5.

Explaination:

a= x&&y&&z++;
1&&0&&5++;
0&&5++;
But the logical operators && and || never checks the right side expression if lhs are 0 & 1 respectively.

So && in 0&&5++ doesn't check 5++ condition.

So z=5.

Parveen said:   1 decade ago
According to my point of view,

32 is represented as 00000000 00000000 00000000 00100000 for gcc compiler and for c compiler 00000000 00100000.

And 4 is represented as 00000000 00000000 00000000 00000100 for gcc compiler and for c compiler 00000000 00000100.

So when we use ~ (4) it will be like.

For gcc compiler 11111111 11111111 11111111 11111011

For turboc compiler 11111111 11111011

So when we apply & operation then for gcc compiler.

00000000 00000000 00000000 00100000

& 11111111 11111111 11111111 11111011
-----------------------------------------

00000000 00000000 00000000 00100000

-----------------------------------------

Which is equal to 32?

For turbo c compiler.

00000000 00100000

& 11111111 11111011

---------------------------------------

00000000 00100000

---------------------------------------

Which is equal to 32?
(1)

Harsh said:   6 years ago
@Datta is right.
(1)

Jabya said:   3 years ago
Shifting operations done only on positive numbers.


Post your comments here:

Your comments will be displayed after verification.