
Here, $\texttt{sum}$ is a static variable.
So, there is only one copy of $\texttt{sum}$, and it keeps its value across recursive calls.
Initially, $\texttt{sum = 0}$.
For $\texttt{fun(5)}$:
$\texttt{sum = 0 + 5 = 5}$, then it calls $\texttt{fun(3)}$.
For $\texttt{fun(3)}$:
$\texttt{sum = 5 + 3 = 8}$, then it calls $\texttt{fun(1)}$.
For $\texttt{fun(1)}$:
$\texttt{sum = 8 + 1 = 9}$, then it calls $\texttt{fun(-1)}$.
For $\texttt{fun(-1)}$, the base condition is true, so it returns $\texttt{sum}$.
So, $\texttt{fun(-1)}$ returns $\texttt{9}$.
Now returning starts.
In $\texttt{fun(1)}$, $\texttt{temp = 9}$ and current $\texttt{sum = 9}$.
So, $\texttt{fun(1)}$ returns $\texttt{9 + 9 = 18}$.
In $\texttt{fun(3)}$, $\texttt{temp = 18}$ and current $\texttt{sum = 9}$.
So, $\texttt{fun(3)}$ returns $\texttt{18 + 9 = 27}$.
In $\texttt{fun(5)}$, $\texttt{temp = 27}$ and current $\texttt{sum = 9}$.
So, $\texttt{fun(5)}$ returns $\texttt{27 + 9 = 36}$.
$\therefore$ Output $:\texttt{36}$