In the program below, why is ~a
printed in the output as 10
? Why not -11
?
#include <stdio.h>
int main()
{
int a=10;
~a;
printf("complement : %d\n",a);
}
In the program below, why is ~a
printed in the output as 10
? Why not -11
?
#include <stdio.h>
int main()
{
int a=10;
~a;
printf("complement : %d\n",a);
}
Because you don't save the result of the complement operation anywhere.
If you do e.g.
a = ~a;
then you should get a different result.
Or you could simply print the result of the operation:
printf("complement : %d\n", ~a);