Using function arguments as local variables
Posted
by Rubys
on Stack Overflow
See other posts from Stack Overflow
or by Rubys
Published on 2010-05-02T12:53:32Z
Indexed on
2010/05/02
12:57 UTC
Read the original article
Hit count: 183
best-practices
|subjective
Something like this (yes, this doesn't deal with some edge cases - that's not the point):
int CountDigits(int num) { int count = 1; while (num >= 10) { count++; num /= 10; } return count; }
What's your opinion about this? That is, using function arguments as local variables.
Both are placed on the stack, and pretty much identical performance wise, I'm wondering about the best-practices aspects of this.
I feel like an idiot when I add an additional and quite redundant line to that function consisting of int numCopy = num
, however it does bug me.
What do you think? Should this be avoided?
© Stack Overflow or respective owner