Getting miscellaneous answers

in my code of line 42, if i am writing -->return ans then the output is 0.
And if i am writing -->return ans+1 then i am getting right ans.

please tell me why this is happening,

ans variable basically represents the number of recursive call you have done till now. This needs to be incremented always after each recursive call. This is why ans+1 has ben done. Without doing this, the ans variable will not get updated. If the search element is found, it will not print the index but 0(always).

Consider this case:
1
5
2 3 2 2 4
2

On the 0th recursive call only you will find the search element that is 2. So your function will return 0.
Say, now you have to search for element 4. On the 4th recursive call,you will find the element. So the return value will be 4.

Do a dry run. You will understand it better.