+ 1
Why is this program changing the value of variable B even if it is declared as static?
/* Why is this program changing the value of variable B even if it is declared as static?*/ #include <stdio.h> using namespace std; void fn() { int a=10; static int b=20; printf("a=%d b=%d",++a,++b); } int main() { fn(); fn(); return 0; }
6 ответов
+ 3
i think you are confusing static with a constant
+ 3
Static => initialize only once.
constant => once declared, can't modify it's value
I think u looking for is constant.
+ 3
@Rajesh use the keyword const instead of static
+ 2
Use const instead.
+ 1
@Edward yes sir I am confused with static variable 😔
+ 1
@Eranga thanks