[Q] when to use pointer and when to use reference?

E

Eric

Yuming Ma said:
this is an interview question.

I tend to use a reference by default.

However, for example, when it is useful to be able to check to see if a
parameter is NULL to help determine how a function behaves, then I will
use a pointer.
 
L

lilburne

Yuming said:
this is an interview question.

Depends on context of the question.

Mainly if the reference needs to be 'reassigned' use a pointer.

Then there are style issues. For example some styles would
have you use a const reference for input parameters to a
function and a non-const pointer for output parameters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top