0

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);

1

& 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.

https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbclx01/cplr233.htm

You must log in to answer this question.

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