Function Return Statement

3 minutes
Share the link to this page
Copied
  Completed
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after where the subroutine was called, known as its return address. The return address is saved, usually on the process's call stack, as part of the operation of making the subroutine call. Return statements in many languages allow a function to specify a return value to be passed back to the code that called the function.

Transcript

Hello, welcome to the 30th tutorial in the c++ programming series. And in this part we'll be looking at the function return statement. return statement for functions allow you to enter a function and return a value to the location the function was called. So don't have to reach the end of the function up if you call the return statement ended at that particular point. But again, it also returns the value so Laura common practice in code is for you to actually do something with the function and then return that value. Obviously, the function or has a certain purpose that lets us open up that project and show you how to implement a function we will return statement.

This is an example of a function where it returns them and the main entry point for your application is the return type in the previous part we looked at or just use void which doesn't return anything, you can still technically use a return statement where you just put like return without value, and that just That function, but let's show you a functional inequality, I'm going to use toppling can be any data type, you can even return user defined objects as well, which we'll be covering later on. So you do int, then the function name. It's the same before, so return function. And in here, we're going to return the value 76 days literally what you do, and if I were to just get rid of this nine second and then see if giving me an error, think control at the end of non void function. Basically, if you have return talk, you have to have a return statement.

So you're calling this like how an if statement, the condition statement, have a return statement in there, because if for some reason it doesn't hit, it doesn't validate as true the estimate their turn when they're recorded. We might have an hour so we might haven't returned Afterwards we can that's common practice. That's a okay but you can't just not have return statements all basically the flow within the function that we'll get to. Well, a no return statement there was going to put return 17 against Assad running for the purpose of this tutorial. We are going to just see if we can get by managers love to see it is great for teaching purposes in the return function and issue brackets because that's what differentiates a variable and a function called STD line semicolon there we run this we get the value seven six, basically this function is called and this value so we do some six times by two so it should be hundred and 52.

You get the value hundred 52. Again, you can do whatever you want in this location. You can call it several times. That is it for the function return statement. In the next part we're going to be looking at function arguments passed by Valley sorry about this low YouTube notification. Actually just saying your video is now on YouTube back in the previous video.

Yeah, the next part we'll be looking at function arguments passed by value, or the requirements or source code will also be in the description. In the description. They will also be our email address, which is support as seminar system coder UK. You can comment on this video with historic investments or YouTube, whatever you feel comfortable with. And as usual, thanks for watching and I hope you have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.