The following implementation on a fixed number of functions with a number, and returns, there is something wrong in the following implementation, please point out, and correct,
Int add_n (int n)
{
Static int I=100;
I +=n;
return i;
}
CodePudding user response:
If want to fixed plus 100 every time, and returns, then error is static this sentence, remove the this sentence is right,Because there is static, the variable is initialized only once, such as n=5 I=100 + 5=105; So the next time you call add_n function, I will become 105, and won't initialize I=100.
CodePudding user response:
If want to fixed plus 100 every time, and returns, then error is static this sentence, at the back of the simpleCodePudding user response:
Static is static, remove the static