C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 4)
4.
If an unsigned int is 2 bytes wide then, What will be the output of the program ?
#include<stdio.h>

int main()
{
    unsigned int a=0xffff;
    ~a;
    printf("%x\n", a);
    return 0;
}
ffff
0000
00ff
ddfd
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
47 comments Page 5 of 5.

Sohan lal mits said:   1 decade ago
Only ~a does not restored the value in a so finaly output is same as previous as assign.

Naumi said:   1 decade ago
It is like Lvalue is not present therr ...Lvalue is a conatiner/variable on left side of the expression.....which would have contained the value of ~a.

Nirlep said:   1 decade ago
~a does not assigned any where yaar
so simple

Youssef said:   1 decade ago
0xfff = 1111 1111 1111 1111
and ~a is not a=~a
~a dose not affect the value of a

Pratik said:   1 decade ago
Can you explain in detail how answer is a?

Sundar said:   2 decades ago
Hi Ranjit,

The modified value is not stored in 'a' back.

If we write like this a = ~a; we can find the changes by ~ operator.

Hope you understand it. Have a nice day!

Ranjit said:   2 decades ago
Can any explain why ~operator has no effect here?


Post your comments here:

Your comments will be displayed after verification.