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.
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.
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?
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?
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?
Jailani said:
1 decade ago
No matter about 0x it is just a hexadecimal representation and also it is optional.
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!
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
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
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers