Parameter passed by value:View more random threads:
- what are Templates?
- why we use pointers or reference except using real name of...
- tool of trade in c++ May 2011
- C++ Random crash 2011
- HELP with do loop
- Sorting code in c++
- Difference b/w encapsulation and information hiding
- excuteing the progreme and how does can i best my programe...
- question adout c++ 2011
- define identity of object, how do we handle processes in...
When we call a function with parameter we pass the copies of their values.
For example
Int x=2, y= 3, z;
z= addition (x,y);
What we did that we pass the value of x and y ( i.e. 2 and 3 )to our desired function.
Parameter passed by reference:
Sponsored Links
In parameter passed by reference, the first thing is that in the declaration of our function the type of each parameter was followed by an ampersand sign (&). This ampersand is what specifies that their corresponding arguments are to be passed by reference instead of by value. When a variable is passed by reference we are not passing a copy of its value, but we are somehow passing the variable itself to the function and any modification that we do to the local variables will have an effect in their counterpart variables passed as arguments in the call to the function.
Example
Void addition (int & a, int & b, int & c)
{
a * = 1;
b* = 2;
c* = 3;
}
Now when we call the function
int x=5, y=3, z=2;
addition (x, y, z);
Here x, y, z will be passed by reference to our original addition function.
There are currently 1 users browsing this thread. (0 members and 1 guests)