What does only fallback do in C ++?
I read an example about looking up gcd which is Greatest Common Divisor but only uses return in the following code. What is it? Can returns be used this way? I have searched about this and nothing seems to make me understand. Please .. Here's the code:
void fraction::lowterms ()
{
long tnum, tden, temp, gcd;// num = numerator and den = denumator
tnum = labs (num);
tden = labs (den);
if ( tden == 0)
{
exit (-1);
}
else if ( tnum == 0)
{
num = 0;
den = 1;
return; //why return alone used here???
}
}
source to share
In this case, nothing but the completion of the function (which would have happened anyway)
The return type of this function void
means that it does not return any value.
However, as a rule, the operator return
stops this function, returns the specified value, then no further code in this function is executed. In this case, it was at the end of the function, so it doesn't add anything.
source to share
Each function returns to the caller (more precisely, the command after the call) at the end, so there is always a return, even in a function with a void return (where the compiler adds return;
to the body, the programmer doesn't need to worry about that). With the manually inserted return, you have created a different exit point for your function.
source to share