+ 2

What does it mean for a function to return a value?and where does it return?

25th Nov 2019, 2:10 AM
mumtahina rahman
mumtahina rahman - avatar
2 Réponses
+ 1
You write a function either asking it to print something on your behalf and not return anything. Or if you say to the function that I'm giving you a value, so kindly process it and give me the updated result then it can do that as well by returning something. It returns to where you have called it inside the main method.
25th Nov 2019, 2:35 AM
Avinesh
Avinesh - avatar
+ 1
here is an analogy. think of an restaurant you are the waiter. when you recieve an order, you immidiately write them down and give it to the kitchen (pass an argument). they cook for a while and give the food back to you (return the value) to be served. if i write it in code. function kitchen(order) //cook the food written in the order return food function main() //order recieve order = new Order ('burrito') //send the order to kitchen served_food = kitchen(order) // ^ take the food when done as served_food
25th Nov 2019, 2:51 AM
Taste
Taste - avatar