0

What is mean by pass by value

10th Oct 2016, 10:39 PM
lahana
2 ответов
+ 1
Functions are used to increase the reusability of the code..So whenever we are calling the functions it is also possible to pass the data to the functions,process them and display the result... There are two ways by which you can pass the data.. 1) Pass by value 2) pass by reference Pass by value copies the value of actual parameter to formal parameter and then process...any changes that are made to formal parameters are not reflected back to actual parameters...the advantage if this method is the code performs faster.. Pass by reference passes a reference of actual parameter to formal parameter so any changes made to formal parameters are reflected back to actual parameters..
11th Oct 2016, 3:13 AM
Balaji Rs
Balaji Rs - avatar
0
Some examples are: void swap(int x, int y){ int temp = x; x = y; y = temp; } If you call this: int x = 0; int y = 3; swap(x,y); //x =0, y = 3 This is because when you pass by value you simply make copies of the variable to use in the function. The function only gets copies. If the function was: void swap(int* x, int* y){ int temp = *x; *x = *y; *y = temp; } Now when you call swap: swap(&x,&y); This time you are passing the LOCATION of the variables. The referencing operator(&) returns the location of the variable. And the derefrencing operator(*) gets the value at the address. You are passing the location of the variable and from this you get and access the same variable. Hope this helped!
13th Dec 2016, 4:21 AM
Gabe Maxfield
Gabe Maxfield - avatar