Hi guys, in this video, we're going to be talking about pointers. So a pointer is just a variable, it stores the address of another variable. So let's see that in action. So let's say m one is equal to two. Now my pointer is going to be the address of m one. And we're simply going to print out the pointer.
So let's see what happens if we printed out the memory address. So what happened was that we initialize this variable to do we store the address of m one in our variable pointer, and we printed out the pointer. This is a hexadecimal representation of the address of where m one is actually stored. Now, the and symbol is called the referencing symbol. It's also called the reference operator, which is used to get the address of a variable to get the value the data which is stored inside and address, you dereference that pointer. So by default, dereference reaming star So if you didn't start Vidya is going to print it.
So let's see how in action, we can actually leverage this functionality. So I'm going to be showing you an example of pass by value and pass by reference. So we do a function swap function swap takes two variable variables, m one m two, both of type int. So we can do an M one comma m to start and because both of these are of the type size and then we declare a temporary variable to hold the values temporarily, of type int. So we can do a temp is equal to start off in one. Start of him is going to be equal to start a family and then start from one is going to be equal to now what we can do is we can declare two variables and when Do my name to each other equal to two and three respectively.
So I'm going to be printing m One, two. Let's swap with both of these variables. So by if you want to pass a pointer to a function, you can simply reference it using add. So add m one, and m one and m two. And then you simply do FMT dot print line. And we're going to, so let's see what happens.
Oh, yeah, we had two and three and later, we had three and two. So we actually went to the address of where m one and m two were stored, and we swapped out both of these variables. So you might not see pointers in languages like Python. In Python, they only have one this pointer, but in this case, pointers are widely used in code. Thank you.