how return works in c++ code example
Example 1: return function in cpp
// Multiple return statements often increase complexity.
int max(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}//end max
Example 2: return function in cpp
// 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