I have this program that I am trying to understand, what does the & mean and what is it's purpose?

void fun(int &a, float &b);


& is the reference operator, which returns the actual address in memory of a value.

Here, the function declaration is asking to be passed the addresses in memory of an int and a float, rather than the values of an int and a float.

The main difference in practice is that this allows the function to modify the original variables passed to it.

It is similar to passing by pointer:

void fun(int *a, float *b);

The difference is that with the pointer version, the pointers can be NULL, or reassigned in the function to point elsewhere.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .