### palindrome recursive

 ``12345678910`` ``````bool is_palin(string temp,int begin,int end){ cout << temp[begin] << " and " << temp[end] <

this is the recursive function i wrote for palindrome

I just surprise that
`return is_palin(temp,begin+1,end-1);`
this
` is_palin(temp,begin+1,end-1);`
that

make the result differently

any one can explain professionaly?
that this that...

Huh? Are you meaning that if you don't return the result of the recursive call is different? Well naturally, since now one of the control paths doesn't return a value.
A recursive function essentially constructs a loop of calling itself and then unwinds the loop at a return statement that does not call itself. In other words,

Defining statement #1 to be:

 `` `` ``return is_palin(temp, begin+1, end-1);``

and statement #2 to be:

 `` `` ``is_palin(temp, begin+1, end-1);``

While both statements construct the loop of calling itself, in the unwinding of statement #1 after a return true or return false statement, the true/false result is passed back up the tree called by return is_palin(...); in statement #2, the return value of true/false is lost as it goes back up the function calls of is_palin(...) because the function calls don't return a value
Topic archived. No new replies allowed.