+ 6

Is call by reference and call by address same?

5th Mar 2017, 11:39 AM
Rakshita Singhal
Rakshita Singhal - avatar
15 ответов
+ 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
13th Jun 2017, 10:55 AM
Bruh
+ 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
5th Mar 2017, 12:36 PM
Sakshi👸
Sakshi👸 - avatar
+ 4
sorry I didn't read it properly...you were asking for reference and address, and I thought reference and value
5th Mar 2017, 12:25 PM
Sakshi👸
Sakshi👸 - avatar
+ 2
so what's the difference? plz explain
5th Mar 2017, 12:12 PM
Rakshita Singhal
Rakshita Singhal - avatar
+ 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.
12th Mar 2017, 12:37 PM
Manpreet Singh
Manpreet Singh - avatar
+ 2
thank you @Aayushman
13th Jun 2017, 10:57 AM
Rakshita Singhal
Rakshita Singhal - avatar
+ 2
Thanks, do you like new Java projects?
13th Jun 2017, 10:59 AM
Bruh
+ 2
Till now we are a team of 3 students
13th Jun 2017, 10:59 AM
Bruh
+ 2
We come up with ideas and make Android apps / games as projects
13th Jun 2017, 11:00 AM
Bruh
+ 2
I am from India other 2 are from Netherlands
13th Jun 2017, 11:00 AM
Bruh
+ 2
My age: 15
13th Jun 2017, 11:01 AM
Bruh
+ 2
Please tell if you would like to join our team
13th Jun 2017, 11:01 AM
Bruh
+ 2
@Rakshita. Are you interested? please tell. Just don't underestimate the power of a student
13th Jun 2017, 11:27 AM
Bruh
+ 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). :))..
16th Mar 2017, 8:46 AM
Chirag Lathi
Chirag Lathi - avatar
+ 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.
29th Mar 2017, 4:44 AM
ram kumar
ram kumar - avatar