I noticed that a lot of top programmers use unsigned types when you don't need negative numbers, but is it good practice to do so or should you avoid it?
I noticed that a lot of top programmers use unsigned types when you don't need negative numbers, but is it good practice to do so or should you avoid it?
| # | User | Rating |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3447 |
| 6 | Um_nik | 3387 |
| 7 | heuristica | 3322 |
| 8 | turmax | 3317 |
| 9 | tourist | 3307 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 142 |
| 5 | Errichto | 139 |
| 6 | adamant | 137 |
| 7 | AmShZ | 135 |
| 8 | BledDest | 132 |
| 8 | maroonrk | 132 |
| 10 | qwexd | 129 |
| Name |
|---|



In short: No.
Why? because it doesn't improves speed or memory at all and also does overflows (underflow) if it goes under 0 and in some problems you need to work with values under 0, (for example: 2033A - Sakurako and Kosuke) and if you use unsigned you are probably going to receive errors, and if you want to use unsigned you have to be careful and it's just some additional headache so I really recommend not using it.
Ok, thank you
Only use them for bit manipulation because the operators will work as you would expect. Look up how 2s complement representation works with bit shifts if you want to learn more.