In the context of programming, what does Return do?

555 views

I’m trying to pick up computer programming yet again, and I’m not really understanding the use of Return. What is it? How would you use it?

In: Technology

5 Answers

Anonymous 0 Comments

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.

You are viewing 1 out of 5 answers, click here to view all answers.