What does "* & " mean in a parameter?

Feb 15, 2012 at 9:07pm
This is a problem listed at the end of a book I've been reading and this one really stumped me:

In some circumstances when implementing recursive operations on linked lists, the parameter to the recursive method is declared using a syntax similar to someOper(ListNode * & listPtr). What's the purpose of the *& in that declaration. Why is it necessary?

Can anyone help me out?
Last edited on Feb 15, 2012 at 9:08pm
Feb 15, 2012 at 9:24pm
closed account (3TkL1hU5)
http://bit.ly/zlbAdf
Feb 15, 2012 at 9:35pm
Hi

in -> (ListNode * & listPtr) -> listPtr is a refrence to
a pointer of type ListNode

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
struct Int{

	int i;
};

void boo(Int* &a){
	a->i = 3;
}

int main() {

	Int t ;
	t.i = 2;
	Int *b = &t;
	cout<< b->i<<endl;
	boo( b );
	cout<<b->i<<endl;
	return 0;
}
Last edited on Feb 15, 2012 at 9:37pm
Feb 15, 2012 at 9:49pm
closed account (zb0S216C)
It signifies a reference to a pointer.

Wazzak
Topic archived. No new replies allowed.