In C++, you use the ampersand (&) operator in the parameter list (e.g., void modify(int &x)) to pass a variable by reference.
Pass by Value vs Pass by Reference Explained
How do you pass by reference in C++?
The answer
More FAQs in Pass by Value vs Pass by Reference Explained
Pass by Value means a copy of the variable's data is passed to the function. Modifications inside the function do not affect the original variable.
Pass by Reference means the memory address of the variable is passed. Modifications inside the function will alter the original variable's data.
Java is strictly pass-by-value. However, for objects/arrays, the 'value' passed is the memory reference, which allows the object's contents to be modified.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.