Imagine you have a function called ADD(a,b) that, unsurprisingly, adds the value of a and b.
it could look something like this
int add(int a,int b){
return a + b;
}
and we’d use it like
int sum = add(4,6); //sum is now 10
Return in this context should be pretty obvious: it’s what returns the answer we’ve asked for.
Return does two things:
* it stops the current function that’s being executed and jumps back to whichever piece of code was running that called the function
* It gives back a value (usually the result of some calculation) that the code that called it can use in it’s own calculation.
Latest Answers