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 1 of 5.

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

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!

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

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

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

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.

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.

Nikita said:   1 decade ago
Is ~a; a valid statement?

If we write a++ or ++a there is still no left sise variable but it changes 'a' so why not ~a changes 'a'.

Chandu said:   1 decade ago
The modified variable(~a) must be assigned to another or same(a) variable. then only value will be changed.

Ex:-
a=~a;

Durgaprasad said:   1 decade ago
And also NONE OF THE GIVEN ANSWERS ARE CORRECT... becoz when int size is 2 and print that int it will print ffffffff(8 fs).. I have checked it .. So be careful...

Answer here is ffffffff


Post your comments here:

Your comments will be displayed after verification.