code_fille's blog

By code_fille, 9 years ago, In English
int main() 
{
	//Beauty is in relaxed hard work.
	//SSGCA :)
	//Keep doing your thing, complexity would turn into simplicity! :)
    unsigned short int a=0xffff; 
    ~a;
    printf("%x",a);
	return 0;
}

Why does this program output 'ffff' and not 0000?

  • Vote: I like it
  • -11
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it
a = ~a;
  • »
    »
    9 years ago, # ^ |
    Rev. 3   Vote: I like it -11 Vote: I do not like it

    yeah, but why doesn't 'a' get complemented on application of '~'?

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      [~a;] is not doing anything over the variable a. You are using a copy of variable a to do something (~) without assign this result to anybody.