node *head=NULL;
I don' undertand what does above code does? Could you help me ? Thanks,
node *head=NULL;
I don' undertand what does above code does? Could you help me ? Thanks,
This here
node *head
Defines a pointer to a node
, and calls that pointer head
.
=NULL;
Here, NULL
is assigned to it. According to this, NULL
is:
The macro NULL is an implementation-defined null pointer constant, which may be
an integral constant expression rvalue of integer type that evaluates to zero (until C++11)
an integer literal with value zero, or a prvalue of type std::nullptr_t (since C++11)
In the end, the result is that head
holds a value of 0
. This way it can be queried, for instance using if (head == NULL){...
or something similar.
When NULL
is assigned to a pointer, this usually signifies that it's not pointing to a valid object (yet).
NULL
is the macro defined for representing a pointer without a defined address. You can read more about in https://en.cppreference.com/w/cpp/types/NULL