Why is int rather than unsigned int used for C and C++ for loops?

后端 未结 10 2104
日久生厌
日久生厌 2020-12-02 15:50

This is a rather silly question but why is int commonly used instead of unsigned int when defining a for loop for an array in C or C++?

<         


        
10条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 15:59

    Because unless you have an array with size bigger than two gigabyts of type char, or 4 gigabytes of type short or 8 gigabytes of type int etc, it doesn't really matter if the variable is signed or not.

    So, why type more when you can type less?

提交回复
热议问题