+ 1
unsigned modifier holds only positive value. Then why it gives something random positive integer on assigning -ve value?
unsigned int a = -1; gives 4294967295 which is max value of unsigned int and for -2 4294967294 basically starting reverse from max on -ve values. Explain?
4 odpowiedzi
+ 2
Why so? I believe it's due to the effect of integer overflow 👇
https://en.m.wikipedia.org/wiki/Integer_overflow
+ 2
`unsigned int` is 32bit integer with 0 as min value, and (2 ^ 32) - 1 as max value.
2 ^ 32 => 4.294.967.296
When you try to assign a negative value for an `unsigned int` variable, add the max value above by the negative value.
4.294.967.296 + (-1) => 4.294.967.295
4.294.967.296 + (-2) => 4.294.967.294
And so on ...
+ 1
Ipang but why so?
;-;
+ 1
Yeah get it now thank you Ipang