Why is argc an 'int' (rather than an 'unsigned int')?

后端 未结 13 2243
心在旅途
心在旅途 2021-01-31 01:37

Why is the command line arguments count variable (traditionally argc) an int instead of an unsigned int? Is there a technical reason for t

13条回答
  •  梦毁少年i
    2021-01-31 02:17

    I see how it might seem weird: argc should not be negative! But look at it this way: both int and unsigned int cover the range of values you'd accept (if you have 2^31 command line parameters, you have a problem) and int is shorter to type.

    Interview puzzle question: how many keyboards would have been used up typing the unsigned if C had gone with unsigned int argc?

提交回复
热议问题