The code below does exactly the same thing. Which is better to use in terms of optimization? In what instances would you choose pointers instead of references; what instances would you choose references instead of pointers?
I would use references wherever I can, and avoid pointers wherever I can.
I think that a feature that you're not using is more important for these functions, namely const qualifying your variables, since these functions shouldn't modify the strings.
In other words a reference is always to a valid object, but the pointer can be valid, invalid or to an element in an array.
In void printPnt(string *str); the str is a by value parameter, a separate variable that requires space (memory for one address). A reference is not a variable.
The code below does exactly the same thing. Which is better to use in terms of optimization?
References are easier to use and does not produce garbage looking code. Optimisaton-wise both are usually equivalent. References might have and edge over pointers in theory, nowever I never seen it in practice, usually compilers are smart enough to optimise pointer access as they do wiht references.
In what instances would you choose pointers instead of references
When you need to rebind it (references are not rebindable) or point to nothing (there is no such thing as null reference)
what instances would you choose references instead of pointers?
Anywhere where I not reqired to use pointers. Have to do so if I want to pass temporary objects.
BTW, your code is not const correct. Fixed code and example of reference-only semantic: