+ 1
I wana ask that what is the need of pass by value and pass by reference , and are the working of these two , give me detail note
If possible then plzzz explain with example
5 Antworten
+ 16
When you pass by value, there is no change made in the variable values passed
whereas
when you pass by reference i.e by sending an address, changes can be made by accessing that value through address.
+ 3
thnxx both of u to comment on my question it helps me alot
+ 3
specially thnxx to amine boulouma to give me an example
+ 1
It sample: When you passe bye value you don't change your initial variable and when you pass it by reference you are changing the initial variable, example:
void functionParameter (int a){a=6;}
void functionReference (int &a){a=6;}
void main (){
int a= 10;
functionParameter(a);
print ("%d",a) // output : 10
functionReference (a);
print("%d",a) // output : 6
}
And why is that? because you put the & sign that refers to the adress of a that the function go change directly whats inside.
0
Umm I briefly tried to explain and clarify the use & difference of pass by value, pass by reference via reference & pointers, pass by reference in arrays via reference & pointers, & getting a pointer return type from function.
https://code.sololearn.com/cNk82nOx24hw/?ref=app
https://code.sololearn.com/c4dvux5CvxAA/?ref=app