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 3 of 5.
Cherry said:
1 decade ago
Hi. Guys. Here a is absolutely complemented but it didn't assigned to any other variable. So that original 'a' is printed. So simple. Have a great day.
Priya said:
1 decade ago
~ is a unary operator.
Then it should have operated on a and saved the result in the same variable. But why isn't it happening?
Can anyone explain?
Then it should have operated on a and saved the result in the same variable. But why isn't it happening?
Can anyone explain?
Prateek said:
1 decade ago
It is unsigned int so in that highest of the high is supposed to be zero.
So ~0 is = 0-1 = -1.
And as you know in -1 all the bit is set so ffff.
So ~0 is = 0-1 = -1.
And as you know in -1 all the bit is set so ffff.
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.
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)
Deepak Kumar Dubey said:
1 decade ago
int i=4, j=8;
printf("%d %d %d\n",i|j&j|i,i|j&&j|i,i^j);
Can some explain me the way above question going to work.
printf("%d %d %d\n",i|j&j|i,i|j&&j|i,i^j);
Can some explain me the way above question going to work.
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'.
If we write a++ or ++a there is still no left sise variable but it changes 'a' so why not ~a changes 'a'.
Sree said:
1 decade ago
@Rishabh: 0Xffff means 1111 1111 1111 1111. u knew digital systems rite? In that how will u specify 15 in hexadecimal form? 'F' na?
Sravan said:
1 decade ago
Your compiler has been taking four bytes for int so you have got that answer. If you write as a = 0xffffffff.
Then you will get 0.
Then you will get 0.
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;
Ex:-
a=~a;
Deepak kumar Dubey said:
1 decade ago
What will be the order of printing?
int i=4, j=8;
printf("%d %d %d\n",i|j&j|i,i|j&&j|i,i^j);
int i=4, j=8;
printf("%d %d %d\n",i|j&j|i,i|j&&j|i,i^j);
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers