Pointer and reference

Sorry for my naive question.
I have been working with c++ for a short time and I never understood well when I should pass a vector or matrix by pointer or by address to a function.
I read a lot of stuff about this, I know what is the pointer and reference but when it comes to use that I never get the idea. I would be really grateful if you could give me one clear explanation.
Follow the "normal" rules in the C++ Core Guidelines:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#fcall-parameter-passing
When you pass a pointer, you're passing an object with type pointer to some object. The compiler passes what ever address is contained in your pointer. It the called function, you use pointer semantics. i.e. *ptr to dereference the pointer. -> If the pointer is to a struct member or a member of a class.

When you pass a reference, the compiler is still passing an address, but that's transparent to you. The reference is simply another name of the object in the calling function. No need to dereference an object. You use . (dot) to reference members of a struct or other object passed by reference.

Thanks for your answer.
pass by reference unless you can demonstrate a clear need to use a pointer instead (including in place code that expects a pointer for the parameter).
Topic archived. No new replies allowed.