Reference of your integer a
will be passed as argument to your function. Now in your function, if you change the value pointed by r
, it will be reflected in a
as well.
So if you assign r=2
in your function and print out a
in main, you will see that a
has the value 2.
Your program has some syntax errors, but I can understand what you wanted to convey.
Edit:
From the user perspective, it's as if you were receiving a value in the function except that modification done to it are visible from the caller. It's also cheaper in terms of performance when passing big objects because no copy is needed.
How it works in practice is that the compiler actually pass a pointer to the function. But since the caller must have a valid object to pass to the function, a reference can't be invalid contrary to a pointer so you don't need to check for NULL
values.