Check out example codes for "return function in cpp". It will help you in understanding the concepts better.

Code Example 1

Return statement. 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.

Code Example 2

// Single return at end often improves readability.
int max(int a, int b) {
    int maxval;
    if (a > b) {
        maxval = a;
    } else {
        maxval = b;
    }
    return maxval;
}//end max

Code Example 3

// Multiple return statements often increase complexity.
int max(int a, int b) {
    if (a > b) {
        return a;
    } else {
        return b;
    }
}//end max

Code Example 4

void printChars(char c, int count) {
    for (int i=0; i<count; i++) {
       cout << c;
    }//end for
   
    return;  // Optional because it's a void function
}//end printChars

Learn ReactJs, React Native from akashmittal.com