UNSIGNED INT DOUBT

HEY,
IF I DO,
unsigned int x = -8;
cout<<x;
The, the value of (x) showing is very large.
why is it so?

@CODER_JATIN unsigned can only contain positive values
hope its clear if yes dont forget to hit like and mark resolved :smiley:

yes, i know that unsigned contains only positive values, but we try to store negative values in it, it is showing very high values, and the values are not garbage values, they are even same in different compilers.

@CODER_JATIN you are not supposed to store neg value so its giving something else you can refer here
(https://stackoverflow.com/questions/2711522/what-happens-if-i-assign-a-negative-value-to-an-unsigned-variable)
(It will assign the bit pattern representing -5 (in 2’s complement) to the unsigned int. Which will be a large unsigned value. For 32 bit ints this will be 2^32 - 5 or 4294967291)

Yes Yes, understood…
thanks ji.

@CODER_JATIN np bro just mark it resolved and hit like if cleared :smiley: