Hello, welcome to the second tutorial c++ programming series. And in this part then we look at function arguments that are passed by reference. In the previous part, we looked at functional items that pass by value by value, when you pass in an old me creates a local copy of is any modification done to that actual argument on isn't internet actually affect the original value or variable, were passing by reference, you can think of it more as is just passing an ID. So if you pass by reference and you modify within a function, then the original value can modify this one. But let's just show you exactly what we mean. The syntax is almost identical to passing by reference to literally one minor difference.
First of all, let's just declare our function. We're just going to do boy math function. That's it. We're going to put the variable to the local variables, I should say number one, number two, and this is how we would have done it before to pass by value but to pass by reference also there's one more difference, you will put the ampersand here, which is also called the and sign. And this just basically states that this is a reference that and what we're going to do is know Bo, t, d, e, and capital C in the last tutorial as well. Number one, and number line, never going to be number one equals eight.
I'm gonna do it I make this equal to 92 in x, x is equal to too so if we pass both of these in the result will be hundred and 94. It should be based on my calculations with a mass function. I'm going to pass in our x TCF, oh STD annoy everyone this. Let's see what we get 109 six and eight, even though the value that we passed in was 98. So if we just copy and paste it and run it before we call it a function, we'll say the original value is 98. Then these two values are passed in, so they get multiplied and they just see that this is just cut this line here for the sake of it really.
And because there's a there's two arguments learn from others do something with both of them. The number one is changed to the value of a two way design who should say, therefore, I had the value of a man. So passing by reference, any changes made to those local variables will affect the original variable we're passing by value will not. And you might think, why would you want to use one win over the other? Well pass by value is, obviously is great when you want to pass in a piece of data and you want that to be. And what would happen means something alerted to the user or stored but if let's say something were to accidentally affect that, for some reason, because we have huge projects that know the programmers, you might get the bug because somebody accidentally put a piece of code in, that shouldn't be where it and if you do modify the variable in the function by by sending by value, then it won't matter about passing by reference.
Would there be certain instances where you do and then in theory, you could just return that value. If you're doing a lot of function calls. That's a lot of processing power required. Therefore pass by reference is you follow up again, it's something you've got to actually join when the situation really arises. That's it for this tutorial. If you have any questions feel free to message us at support at sonar system Dakota UK.
Email will be the description in this video is directing messages via YouTube. In the next tutorial, we'll look at function parameter default values, or the recording for source code will also be in the description. And as usual, thanks for watching and I hope you have a nice day.