I dont understand how return statement works?

#include
#include
using namespace std;

int convertStringtoInt(char *str,int len) {
if(len==1) {
return str[0]-‘0’;
}

cout << str[len-1]-'0' << endl;
return (10*convertStringtoInt(str,len-1)+str[len-1]-'0');

}

int main() {
char str[]=“1234”;

int len=strlen(str);

cout << convertStringtoInt(str,len) << endl;

return 0;

}

hello @premang
The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point, regardless of whether it’s in the middle of a loop, etc.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.