0
Unsigned variables. Why does the result turn out to be -1?
https://sololearn.com/compiler-playground/cNmkSFoPLsZa/?ref=app https://sololearn.com/compiler-playground/cNmkSFoPLsZa/?ref=app
2 Respuestas
+ 2
anofris
a is UINT_MAX. It will overflow int. That's the cause of your -1 result.
you should be using %u not %d since your variable a is an unsigned int.
Because UINT_MAX > INT_MAX, int wraps back to negative values if you exceed the signed integer max.
And a is 1 more than twice of INT_MAX.
https://sololearn.com/compiler-playground/cmxS5FT5ItNc/?ref=app
+ 1
Thank you very much for your response. I realized my mistake. and yet thank you for your answer, it is unexpectedly accurate and complete.