I have read that "Checking if a reference equals null is meaningless in C++" - because references can never have a null value. But, I see that this statement does not hold in the following example I came up with:
void InsertNode(struct node*& head, int data)
{
cout << head << endl;
node* temp = new node();
temp->data = data;
temp->next = NULL;
if (head == NULL)
head = temp;
else
{
temp->next = head;
head = temp;
}
}
I am checking if (head == NULL). Even though, head is passed as a reference, I am checking if it equals NULL. This contradicts with the statement that I read "Checking if a reference equals null is meaningless in C++" - Could any one please explain if my understanding is right ? Thanks.
structin the parameter list in C++. Separate namespaces for structures and other types only exist in C. - Ulrich Eckhardtif (nullptr == &head). - Jarod42