What does the static keyword do here?
Can anyone explain this piece of code?
CODE1
int &fun()
{
static int x = 10;
int &b =x;
return b;
}
int main()
{
fun() = 3;
cout << fun();
return 0;
}
Output: 3
CODE 2
int &fun()
{
int x = 10;
int &b =x;
return x;
}
int main()
{
fun() = 3;
cout << fun();
return 0;
}
Output: 10
No comments:
Post a Comment