Using function arguments as local variables

前端 未结 9 1344
野的像风
野的像风 2020-12-30 03:57

Something like this (yes, this doesn\'t deal with some edge cases - that\'s not the point):

int CountDigits(int num) {
    int count = 1;
             


        
9条回答
  •  时光取名叫无心
    2020-12-30 04:09

    About C and C++:

    My opinion is that using the parameter as a local variable of the function is fine because it is a local variable already. Why then not use it as such?

    I feel silly too when copying the parameter into a new local variable just to have a modifiable variable to work with.

    But I think this is pretty much a personal opinion. Do it as you like. If you feel sill copying the parameter just because of this, it indicates your personality doesn't like it and then you shouldn't do it.

提交回复
热议问题