Referance in function

I can't seem find this any where
but i asked the question a few months ago about referance in function
something like this
1
2
3
4
5
int & thisIsAFuncction() {
// code here
return 0;
}

what exactly is the & for, is it there just for show
Last edited on
used on the right side of a type it denotes a reference.

A reference is essentially a pointer which can be accessed using non-pointer syntax.

ie,

1
2
3
4
5
6
7
int x;
int* p = &x;
int& r = x;

x = 5;   // Normal syntax
*p = 5; // To assign 5 to the int, you have to "dereference" the pointer using *
r = 5;  // Although internally r is a pointer, you do not need to dereference 
I know what it all mean's with veriable
what about functions declared like this: int & DoSomething()
in a function it's between the return type and function identifier and i'm not talking about parameters
Last edited on
It means the function returns a reference to an integer.
Topic archived. No new replies allowed.