What is a null pointer ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is a null pointer ?

what is the definition of a null pointer ? what are the benefits of it ? TIA

2nd Apr 2018, 5:34 PM
Nieb Hasan
Nieb Hasan - avatar
1 Answer
+ 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)
2nd Apr 2018, 6:03 PM
Alex
Alex - avatar