what is the difference between passing argument by reference and passing function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

what is the difference between passing argument by reference and passing function

17th Sep 2016, 5:49 PM
ADITYA AVADHANI M.L
ADITYA AVADHANI M.L - avatar
3 Answers
+ 4
Pass by value is the regular way you would pass a variable through a function: void seta(int a) { a = 10; } int main() { int a = 5; seta(a); cout << a; //output is 5, because the function created a copy of variable a from main } Pass by reference is when you pass through a variable when the function parameters are that of a memory address using the ampersand (&): void seta(&a) { a = 10; } int main() { int a = 5; seta(a); cout << a; //output is 10, as we passed by reference, allowing the function to modify the variables memory address, rather than creating a copy and modifying that }
18th Sep 2016, 2:43 AM
Cohen Creber
Cohen Creber - avatar
+ 1
@cohen creber nice example @aditya good question
14th Feb 2017, 6:39 PM
aaaa
0
At compile time memory gets allocated and deallocated is called dynamic memory.
17th Sep 2016, 6:11 PM
Geek
Geek - avatar