
Here, $\texttt{total}$ is a static local variable.
A static local variable is initialized only once and keeps its value between function calls.
Initially, $\texttt{total = 1}$.
For $\texttt{i = 1}$, function call is $\texttt{add(1)}$.
So, $\texttt{total = 1 + 1 = 2}$ and $\texttt{ans = 2}$.
For $\texttt{i = 2}$, function call is $\texttt{add(2)}$.
Now $\texttt{total}$ starts from old value $\texttt{2}$.
So, $\texttt{total = 2 + 2 = 4}$ and $\texttt{ans = 4}$.
For $\texttt{i = 3}$, function call is $\texttt{add(3)}$.
Now $\texttt{total}$ starts from old value $\texttt{4}$.
So, $\texttt{total = 4 + 3 = 7}$ and $\texttt{ans = 7}$.
Therefore, the output is $\texttt{7}$.