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
1 Respuesta
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.