C Programming - Bitwise Operators - Discussion

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

int main()
    unsigned int a=0xffff;
    printf("%x\n", a);
    return 0;
Answer: Option
No answer description is available. Let's discuss.
47 comments Page 1 of 5.

Pavan said:   3 years ago

Answer for What is the use of 0x.

It always remember ox represent an upcoming number is a constant and hexagonal number to C compiler.

Rashmi said:   3 years ago
Here ~ has no effect because ~a is not stored back in the variable.
++ operator itself is a self incrementing operator need not be stored.
But a+1 has to be stored back in a.
Like, a = a+1.

Prakash said:   5 years ago
Hi, I am Prakash.

A has not stored any where so it will not affect that is okay but I will take ex: a=1; and I will increment it to a++ but I have not stored anywhere but in the next time if I print a then why will it get effect?

Mohammed Umar said:   6 years ago

int main()
int a=0xffffffff,b;
printf("%x\n", a);
return 0;

I have taken this value then also it prints the same. Can anyone explain properly?

Lakshmi said:   6 years ago
Thanks for explaining it.

Ram khanna said:   8 years ago
As there is unsigned int the value is always positive hence ~ has no effect.

Hope you understood.

Malreddy said:   8 years ago
0xffff = 1111 1111 1111 1111 it is the value is assigned for a ok.

But he/she given that ~a, it doesn't mean that a=~a.

So there is no change in value of a. So a is print as ffff only.

Zeba Anwar said:   9 years ago
Here a = 0*ffff.
Which can also be written as 0000ffff.

So ~a = ffff0000.
Therefore output will be ffff.

Risv said:   9 years ago
a = 1111 1111 1111 1111

Let b =~ a, means b = 0000 0000 0000 0000

Concept : take composite resultant value is b = (-1)*(a+1).
Here 'a' may be +/- in the form of Decimal value.

From above eg:

a = 0xffff.

a = -1 [decimal value of 0xffff].

So due to our concept b =~a => b = (-1)*(-1+1) therefor resultant of b = 0

b = 0 [means hexadecimal value is 0000 0000 0000 0000].

But here from above example:

Line 1: a = 1111 1111 1111 1111

Line 2: ~a = 0000 0000 0000 0000

But value of 'a' does not change in line 2.

So a = 0xffff.

Gopi krishna said:   9 years ago
Thank you @Taruna.

I satisfy with you answer. What about two byte compiler?

Post your comments here:

Your comments will be displayed after verification.