I was reading an article on references in CPP, where I found this example and couldn't understand how is that we are able to call a function and initialize a variable inside its call block. As the moment we value of the function call is returned, the function is out of the call stack all allocated memory is released.
#include <iostream>
using namespace std;
int& fun()
{
    static int x = 10;
    return x;
}
 
int main()
{
    fun() = 30;
    cout << fun();
    return 0;
}
Output: 30
