Hello, and welcome to the 39th tutorial on c++ programming series. And in this part, we're going to be looking at references. A reference variable is an alias that is another name for an already existing variable. So basically, it's not a variable in itself doesn't hold its own unique data. Once a reference is initialized the variable, even the variable name, or the reference name may be used to refer to this variable. So what is the benefit of this in my thing, if I can serve a variable, let's say called I, and that's it, I have a reference called x which is refers to y.
And if I'm a change wired, obviously, I'm so excited to make a change to x effects I one benefit of this if you call it a function, when you call the function, and you pass in a value from or passing a variable, any changes made to that variable is actually local copies of the originals there but isn't affected. But you could use a reference or something called a pointer which we'll be covering in the next part. series which will allow you to affect the original and that's one of the many benefits of a reference. So let's go ahead and show you how to use references. It's like it literally is really, really really easy. So what you're what you want to do is create a variable for the quality I select the value 22 and then we're going to create a reference and to create a reference you put the ampersand, then the name of your reference o p, you assign it a variable that you want it to refer to.
So I so if we do STD colon colon C, to avoid testing you will miss it prints out the value 24 if we were to do p equals nine, now on this, it prints out the value nine and it prints out the value known for like we said, p even a variable in itself is actually alias First to the variable called AI and any change made to P affect AI. That's it for this pie. If you have any questions feel free to message us at support at solar systems coda UK, the email will be in the description you can comment and do this directly messages via YouTube. The next part of this series we'll be looking at pointers. All the recording for source code will also be in the description. As usual.
Thank you for watching and I hope you have a nice day.