Call a function! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Call a function!

Which procedure does it take more memory : pass by value or pass by reference?

7th Jul 2020, 3:45 AM
TeaserCode
5 Answers
0
You need to be a bit more specific bcoz C++ have three methods to pass arguments. Pass by value Pass by reference and Pass by pointer/address Pass by value which means passing arguments like func(a,b) and pass by pointer means passing arguments like func(&a,&b). These both methods will take extra space. If memory is concerned then use pass by reference. Pass by reference's declaration goes like return-type func(type &var, type &var) { //Body } To call function: func(var1,var2) //similar to pass by value This is the declaration of pass by reference function. It works exactly as pass by pointer, which means formal and actual arguments will refer to same memory but the only change is this will not acquire extra space.
7th Jul 2020, 6:29 AM
Alaska
Alaska - avatar
0
Yes I know it, call by value means that function located in main() copies all its parameters to function which we define outside of main(). Can you tell me what are formal parameters? Actual parameters are local to main(), right.
7th Jul 2020, 9:31 AM
TeaserCode
0
Formal parameters are local to function, the variables declared in definition of function.
7th Jul 2020, 9:37 AM
Alaska
Alaska - avatar
0
I think the variables declared in definition of function are global, so formal variables are global. Actual variables are local.
7th Jul 2020, 9:48 AM
TeaserCode
0
No no, variables declared in Definition of function are local to function only. It can't be accessed outside function. Global variables are declared outside main function.
7th Jul 2020, 9:57 AM
Alaska
Alaska - avatar