What does it mean if there is an ampersand right before the function name? Something like:
int& myFunction(int& a, int& b)

Also my book said something about how it doesn't create a copy of something if you pass it by reference, but what exactly does that mean? I never understood that.

Recommended Answers

It means the function returns a integer reference for a return value. In your example prototype the function probably returns a reference to either a or b.

Jump to Post

All 2 Replies

It means the function returns a integer reference for a return value. In your example prototype the function probably returns a reference to either a or b.

>>an ampersand right before the function name

That's the wrong way to think about it. The ampersand is right after the return-type declaration, in other words, the ampersand is part of the definition of the return-type. In this case, the function returns a reference to an int variable. It also takes its two parameters by reference.

Read this for a deeper explanation of references.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.