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.

Malreddy said:   10 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.
(1)

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

Hope you understood.

Lakshmi said:   8 years ago
Thanks for explaining it.

Mohammed Umar said:   8 years ago
#include<stdio.h>

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

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

Prakash said:   6 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?

Rashmi said:   5 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.
(3)

Pavan said:   5 years ago
@All.

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.
(2)


Post your comments here:

Your comments will be displayed after verification.