The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes

what is the output of the following programming????

and am confusing is unsigned int stores signed integer, and 

what is ‘ ’ this symbol ?? and what happened when assigning ‘~0’ to y????? and 

what will be printed when x,y are printing and how …?

can anyone tell me how it happened ..Thankyou…..!


int  main()


   unsigned int x = -1;

   int y = ~0;

   if (x == y)



      printf("not same");

printf("\n x is %u, y is %u", x, y);

   return 0;


in Programming by (171 points) | 23 views

1 Answer

0 votes
1) When you assign the sign bit to unsigned bit then first converted to 2s complement

-1 => 1| 1 where first 1 is sign and second represent value

Now applying sign bit extension rule so 1111...1 upto the size/capacity of x

2) y=~0 means flip bits and represent in 2s complement i.e -(0+1) = -1

3) x==y then from y=-1 it is converted to unsigned which is 1111.1 upto the size/capacity of y which is same as size taken by x

Hence x and y contains same value

so same is printed

And output in 64 bit compiler is 4294967295 4294967295 here also converting signed to unsigned for y
by Junior (823 points)
edited by

nice explanation.....,but am not understanding how 2's complement of 0 will -1. i think 2's complement of 0 is again 0.


read this how '~' working

Conclusion for ~ is that

~N = -(N+1)

okay thank you.......!

Related questions

+2 votes
1 answer
asked Sep 10, 2017 in Programming by atul_21 Active (2.8k points) | 137 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,339 questions
55,763 answers
90,771 users