Hey guys,

I'm very new to C++ and had a really quick question concerning linked lists. So I was wanting to pass a linked list to a function. I realize from another post that I need to put void function(Class * & head) to have it actually do something to the list. I was wondering if anyone could explain to me the difference between passing (Class * head) and passing (Class * & head) is? Sorry if this question is a bit unclear. If I'm missing something fundamental just let me know.

Thanks in advance!

Recommended Answers

The difference is that class* is a pointer passed by value, while class*& is a pointer passed for reference. Another way to do it is to pass class** (note two stars). Its the same idea as passing an int (or anything else for that matter), such as int is passed …

Jump to Post

All 3 Replies

The difference is that class* is a pointer passed by value, while class*& is a pointer passed for reference. Another way to do it is to pass class** (note two stars). Its the same idea as passing an int (or anything else for that matter), such as int is passed by value while int& is passed by reference.

Read this.

Thank you both for your replies. That clears it up for me for the time being. Much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.