+ 6
Is call by reference and call by address same?
15 odpowiedzi
+ 3
@Rakshita when you call by reference the computer knows it's address so it won't be mistaken and when you call by address by your self it might get mistaken Analogy: Like you are going to one's house, you know his address but there's one more society of the same name and house no. is too same so you might go to wrong one (it's a possibility) but if he had sent one person to drop you to his house then you will go to his house only that person acts as a reference
+ 9
basically there is not much difference in both
in call by reference it's confirm that the object being called always exist but in case of call by address the pointer may or may not be null
+ 4
sorry I didn't read it properly...you were asking for reference and address, and I thought reference and value
+ 2
so what's the difference? plz explain
+ 2
Pointers are objects which store memory addresses of other objects. They may contain no address, like NULL. References are not objects, they are just like second name of a variable, just like a same person can have multiple names. As they are not objects, they cannot be empty. They must be assigned to some variables.
If call by reference is done, original object is called directly, as reference is just a second name of the same object.
If call by pointer is done, that pointer is used to call the object whose address is stored in it,using * (dereference) operator. (which might give NULL if nothing is stored in the pointer).
To sum up, they are not the same.
+ 2
thank you @Aayushman
+ 2
Thanks, do you like new Java projects?
+ 2
Till now we are a team of 3 students
+ 2
We come up with ideas and make Android apps / games as projects
+ 2
I am from India other 2 are from Netherlands
+ 2
My age: 15
+ 2
Please tell if you would like to join our team
+ 2
@Rakshita. Are you interested? please tell. Just don't underestimate the power of a student
+ 1
*Just googled your question*
C++ supports all three, plus one.
Pass by value (Type cv name) makes a copy of the original object that exists until the function completes.
Pass by reference (Type cv & name) and pass by (address) pointer (Type cv * name) are often the same, aside from some differences in syntax. The biggest difference is one of convention, not strict enforcement by the language: passing by reference implies that the object being passed always exists, while passing by pointer suggests that it might be nullptr, and should be checked before being accessed. As an aside, this is something that Google's widely disseminated style guide gets horribly, horribly wrong. The mandatory check on pointer parameters should apply to out and inout parameters, not just in.
Technically, pointers are passed by value, but the object they point to is being what other languages would call referenced. This also applies when an object is passed in a smart pointer (assuming the smart pointer is passed by value).
:))..
+ 1
void change(int x, int y){
++x;
++y;
}
int a = 2;
int b = 1;
change(a,b);
cout>>a>>b; // here we get a=2 , b= 1;
int* pa = &a;
int* pb = &b;
change(*pa,*pb);
cout>>a>>b; // here we get a = 3 , b= 2;
when we send a and b as parameter they were actually get copied to x and y(the memory address of a n x are different). which are completely new references. so, changes made on x n y won't reflect on a n b.
when we use pointers, which indeed means, memory address of that particular variable. here, now x holds mem Location of a and y holds mem location of b. so, changes made on x n y are actually changes made on a n b.