+ 2
What is a null pointer ?
what is the definition of a null pointer ? what are the benefits of it ? TIA
1 Réponse
+ 6
A pointer which points to nothing. Technically it actually points to 0, but this just specifies that it's not pointing to an accessable memory location.
The benefit is that you can check if something is assigned to it. This is for example used in linked lists. In a singly linked list each node has a pointer for the memory location of the next node. The last node however has a null pointer. You can iterate through the nodes by checking if the next node is 0, because if an object is assigned to the next node the value is always >0 (because it is stored somewhere in the memory)