0

Can we pass the value by reference without declaring any pointer?

in c or c++ when we call the function by reference we declare a pointer and then pass the reference to it. can we do this without pointer. if yes please give a demo too. Thanks

19th Jan 2018, 3:27 AM
ImranKhan CD
ImranKhan CD - avatar
1 Answer
0
Yeah you can use references. class Foo { ... } void my_function(Foo& foo){ ... } int main(){ Foo my_foo; my_function(my_foo); } In this example my_foo is passed by reference. A pointer is being used under the hood, but you never get to see it.
19th Jan 2018, 3:44 AM
Schindlabua
Schindlabua - avatar