0
Call a function!
Which procedure does it take more memory : pass by value or pass by reference?
5 Réponses
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.
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.
0
Formal parameters are local to function, the variables declared in definition of function.
0
I think the variables declared in definition of function are global, so formal variables are global. Actual variables are local.
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.