What is the purpose of line no.15 in the code?

to whom will it return the ans ???

ans will be return from function
now whenever function is called whole function is executed and at end it will return its ans
from where function is called he will get the ans
in this example at line no 35
cout<<factorial(n)<<endl;
at line no 35 function is called so the return value will be replaced here
now after function call statement will be
cout<<ans<<endl;