+ 3
why not error
about static https://code.sololearn.com/cxM8ybaRbAGW/?ref=app
7 ответов
+ 9
static variables cannot be re-initialized. For example,
1st function call: i = 5, returns 6
2nd function call: i was supposed to be 5 again if it'd be a non-static variable. But since it's static, it won't lose its previous value. So it'll return ++i = 6+1 = 7
3rd function call: same explanation as 2nd function call. It'll return 8
Change your return type from void to int, the output will be: 6 7 8
+ 7
But I'm getting number of errors (it's not supposed to compile) both in Code Playground and CodeBlocks. Which tool are you using to compile?
The return type should be int instead of void.
+ 4
Thank you verymuch that awesome answer. Suraj and Yasmin i'm get it now.
+ 3
static is not constant
+ 2
i use play ground. i so confuse we can't change the static value is true?
+ 2
Static variables are those whose value keep updating at every function call. These can be used when a function needs to change the value of variable .
+ 1
return can not be used to print, the value returned is printed by cout.