0

The pass by reference mechanism provided by c++ internally again uses pointers and is just pass by value or is it something different ?

Shashank V
  • 10,007
  • 2
  • 25
  • 41
  • Initially pass by value, add `&` for reference. – Hatted Rooster Jan 05 '16 at 21:18
  • http://www.embedded.com/electronics-blogs/programming-pointers/4024641/An-Introduction-to-References – Brian Rodriguez Jan 05 '16 at 21:18
  • I don't really think the duplicate linked is a duplicate. But the real answer is: references are either pointers under the hood, or don't exist at all under the hood... meaning they take up no memory on the stack or elsewhere, the thing which they refer to is accessed directly – David Jan 05 '16 at 21:26
  • I've learned that in C, everything is pass by value. Even when using pointers to pass addresses to called function, the addresses are copied into argents of called fucntions so it is again pass by value. So in case of c++ references, when a called function takes a reference arguments, does that mean the compiler copies the address of arguments from calling function to new variables of called function so it is again call by value if looked at implementation details. – Shashank V Jan 05 '16 at 21:36
  • @David One of the answers in the dupe addresses exactly the issue: http://stackoverflow.com/a/596750/3093378. Agree it's not 100% duplicate, but the discussion there is exactly what OP probably wants. – vsoftco Jan 05 '16 at 21:36
  • @aviator The C++ standard does not mandate any restrictions on how a reference is implemented. The address can either be copied into your function, or used directly (e.g. if the reference is stored in the data part of your program). – vsoftco Jan 05 '16 at 21:41
  • @vsoftco Thanks, that answers my question. – Shashank V Jan 05 '16 at 21:48

0 Answers0