Reputation: 111
I'm doing a searching for swapping two nodes of linked list and found out a block of code as follow:
void swapNode(call * &head, call * &first, call * &second) {
// swap values, assuming the payload is an int:
int tempValue = first->value;
first->value = second->value;
second->value = tempValue;
}
My question is what the meaning for put the ampersand after asterisk?
Upvotes: 0
Views: 76
Reputation: 11047
Ampersand (&) here denotes reference
. it is not the address operator.
This is the C++
way of being able to change the value of a passed-in pointer because C/C++ pass parameters by value. In C
, you would use a double pointer to achieve the same.
Upvotes: 1