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;
}
Discussion:
47 comments Page 4 of 5.
Pintu kumat singh said:
1 decade ago
But what will the value of unsigned int =0xffff;
than what about ox if answer be ffff.
Can any one explain it.
than what about ox if answer be ffff.
Can any one explain it.
Zeba Anwar said:
1 decade ago
Here a = 0*ffff.
Which can also be written as 0000ffff.
So ~a = ffff0000.
Therefore output will be ffff.
Which can also be written as 0000ffff.
So ~a = ffff0000.
Therefore output will be ffff.
Ram khanna said:
10 years ago
As there is unsigned int the value is always positive hence ~ has no effect.
Hope you understood.
Hope you understood.
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.
Jailani said:
1 decade ago
No matter about 0x it is just a hexadecimal representation and also it is optional.
Don no 1 said:
1 decade ago
Here ~a is used but not assign a value back to a so that a will not be affected.
Youssef said:
1 decade ago
0xfff = 1111 1111 1111 1111
and ~a is not a=~a
~a dose not affect the value of a
and ~a is not a=~a
~a dose not affect the value of a
Gopi krishna said:
1 decade ago
Thank you @Taruna.
I satisfy with you answer. What about two byte compiler?
I satisfy with you answer. What about two byte compiler?
Gowda said:
1 decade ago
Does the operator ~ preserves sign of variable when applying on it ?
Shan said:
1 decade ago
What does 0Xfff represents? can anyone explain clearly?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers