+ 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

2nd Jan 2017, 2:56 PM
chandraprakash
chandraprakash - avatar
5 Respuestas
+ 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.
2nd Jan 2017, 4:08 PM
Frost
Frost - avatar
+ 3
thnxx both of u to comment on my question it helps me alot
29th Jan 2017, 4:09 AM
chandraprakash
chandraprakash - avatar
+ 3
specially thnxx to amine boulouma to give me an example
29th Jan 2017, 4:10 AM
chandraprakash
chandraprakash - avatar
+ 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.
2nd Jan 2017, 4:09 PM
Amine M. Boulouma
Amine M. Boulouma - avatar
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
9th Sep 2019, 11:29 AM
Nikhil kumar