[Solved] Use of * and &? [closed]


Try looking at * not as being in front of function name, but rather as being behind TreeNode. In other words, that * changes function return type from structure to pointer to a structure.

& in front of variables means that they are, essentially, still pointers, but they can’t be NULL (there are ways to get around that, but that would just confuse the issue further). So vector& preorder means that preorder is pointer (the term used is reference) to vector, but you don’t need to check if that pointer is NULL. You can simply go ahead and use it.

Without much loss you could change those & into *, changing . in your function to -> and things would work the same. I bet assembly code would be exactly the same as well.

15

solved Use of * and &? [closed]