Problem :
A simple question for which I want to find the answer here.
“As parameters to a function, class objects can be passed by reference only.”
void myRefFunction(type myRefVariable)
{
}
void main()
{
myRefFunction(myRefVariable);
}
For a simple data types like int
, float
, etc. a function is called by value.
But if myRefVariable
is the array, only a starting address is passed (even though the function is the call by value function).
If myRefVariable
is the object, also only a address of a object is passed rather than creating the copy and passing it.
So question is does C++ pass the object by reference or value?