Should unsigned ints be used if not necessary?

前端 未结 7 930
醉梦人生
醉梦人生 2020-12-15 05:38

Should one ever declare a variable as an unsigned int if they don\'t require the extra range of values? For example, when declaring the variable in a for loop, if you know i

相关标签:
7条回答
  • 2020-12-15 06:43

    In almost all architectures the cost of signed operation and unsigned operation is the same. So efficiency wise you wont get any advantage for using unsigned over signed. But as you pointed out, if you use unsigned you will have a bigger range

    0 讨论(0)
提交回复
热议问题