could anyone clarify this piece of code for me? I've done some research to understand references and static, but I still don't understand what does static do in this example. And why does it have to be there in the first place (If static is missing, the compiler gives warning and program could possibly crash, why?).
int & foo(int b)
{
static int a = 7;
a += b;
return a;
}
int main() {
int & x = foo(0);
int & y = foo(1);
cout << (x + y);
}